/*
*    Phantom Test Driver v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
/*
 * PTDMain.java
 *
 * Created on September 20, 2005, 6:07 PM
 */

package ptd;

import java.awt.Dimension;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
import javax.swing.JFileChooser;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.JEditorPane;
import java.awt.print.*;
import javax.swing.InputMap;
import javax.swing.KeyStroke;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;

import java.io.File;
import java.util.Vector;
import javax.swing.event.ChangeEvent;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;



import ssi_colorizer.*;
import ptd_suite_objects.*;
import ptd_decl_objects.*;
import closeable_tabbedpane.*;

//import org.eclipse.swt.events.FocusEvent;
//import org.eclipse.swt.events.FocusListener;
import java.awt.Component;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
//import java.awt.Foc

import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.net.URL;
import javax.help.*;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.swing.LookAndFeel;
import javax.swing.text.JTextComponent;

import ssi_linenumberview.*;
import ssi_utilities.ssi_executor;

/**
 *
 * @author  John
 */
public class PTDMain extends JFrame {
        
    FocusListener myFocusListener = new FocusListener(){
        public void focusGained(FocusEvent e){
            //Main.debug_out(e.widget.getClass());
            //Main.debug_out(e.getOppositeComponent().getClass().toString());
            //Main.debug_out("GOT FOCUS!!");
            FocusComponent = (JTextComponent)e.getComponent();
            
        }
        public void focusLost(FocusEvent e){
            //FocusComponent = null;
        }
    };
    
    // -----------------------------------------------------
    public PTDMain() {
        //Main.makeDirs(this);
        //Main.makeDirs();
        PTDOptions.init();
        readOptions();
        
        if(PTDOptions.m_DefaultDirectory.length() > 0){
            File F = new File(PTDOptions.m_DefaultDirectory);
            if(F.exists()&& F.isDirectory()){
                // This will have to be sufficient as you can't change the working directory
                PTDMain.g_CurrentDir = F;
            }else{
                PTDMessageBox.MessageBox("Default Directory does not exist or is not a directory: " + PTDOptions.m_DefaultDirectory);
            }
        }
        
        initComponents();
        init();
        
        //OK, will try to change 
        try{
            LookAndFeel L = UIManager.getLookAndFeel();
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            MainToolBar.updateUI();
            UIManager.setLookAndFeel(L);
        }catch(Exception e){
        }
    }
    

    // -----------------------------------------------------
    private void init(){

        MainMenuBar.remove(TempMenu);
        
        // REGISTRATION CHECK ==============================================
        PTDRegister aReg = new PTDRegister();
        boolean bReg = aReg.CheckKey(PTDOptions.m_LicenseKey);
        if(bReg == false){
            bEvaluationMode = true;
            boolean bExpired = PTDOptions.checkEvalTimer();
            PTDRegistrationFrame aFrame = new PTDRegistrationFrame(bExpired);
            aFrame.setVisible(true);
            while(aFrame.bWaiting){
                try {
                    Thread.currentThread().sleep(10);
                } catch (InterruptedException ex) {
                    Main.debug_out(ex.getMessage());
                }
            }
            bReg = aReg.CheckKey(PTDOptions.m_LicenseKey);
            if(!bReg){
                if(bExpired){
                    PTDMessageBox.MessageBoxWait("Invalid Registration Key.  Evaluation Expired.  Exiting PTD...");
                    dispose();
                    System.exit(0);
                }else{
                    PTDMessageBox.MessageBox("Invalid Registration Key.  Continuing Evaluation...");
                }
            }else{
                PTDOptions.saveToFile(PTDOptions.getOptionsFile());
                bEvaluationMode = false;
            }
        }else{
            bEvaluationMode = false;
        }
        // END REGISTRATION CHECK ==============================================
        
        if(PTDScriptThread.init_dll() > 0){
            bJavaClientInitialized = true;
        }
        
        FocusComponent = null;
        currScriptThread = null;
        OpenWorkspace = new PTDWorkspace();
        bSuiteRunning = false;
        ImageIcon a = PTDImageLoader.getImageIcon(PTDImageLoader.IMG_PTD_ICON);
    
        setIconImage(a.getImage());
        
        MainToolBar = new PTDToolBar();
        getContentPane().add(MainToolBar, java.awt.BorderLayout.NORTH);
        initToolBar();
                
        MainTree = new PTDTree(true);
        MainDecls = new PTDDecls();
        MainFunctions = new PTDFunctions();
        
        PTDConsole MainConsole = new PTDConsole();
        MainConsole.StartThread();
        
        
        
        
        Consoles = new Vector<PTDConsole>();
        Consoles.add(MainConsole);
        
        MainColor = new SSI_ColorPane();
        EditorTabs = new CloseableTabbedPane(true);
        ConsoleTabs = new CloseableTabbedPane(false);
        
        DebugPanel = new PTDDebugPanel(this);
        PTDScriptPane aDebugOutput = new PTDScriptPane();
        aDebugOutput.addFocusListener(myFocusListener);
        DebugPanel.setOutput(aDebugOutput);

        RemotePanel = new PTDRemotePanel(this);
        RemotePanel.addFocusListener(myFocusListener);
        
        SuiteProps = new SuitePanelBase();
        TestcaseProps = new TestcasePanel();
       
        DeclProps = new DeclPanelBase();
        
        EditorTabs.setTabLayoutPolicy(EditorTabs.SCROLL_TAB_LAYOUT);
        ConsoleTabs.setTabLayoutPolicy(ConsoleTabs.SCROLL_TAB_LAYOUT);

        int prefH = this.getHeight() / 4;
        int prefW = this.getWidth();
        ConsoleTabs.setSize(prefH, prefW);
        ConsoleTabs.setPreferredSize(new java.awt.Dimension(prefH, prefW));
        MainPane.setRightComponent(ConsoleTabs);
        
        JScrollPane TreeScroll = new JScrollPane();
        MainTree.setParent(this);
                
        TreeScroll.setViewportView(MainTree);
        TreeScroll.setPreferredSize(new Dimension(200, 400));
        TreeScroll.setSize(200,400);

        
        //TreeScroll.class.getF
                
             
        
               
        
        JScrollPane DeclsScroll = new JScrollPane();
        MainDecls.setParent(this);
        MainDecls.setToolTipText("Drag and Drop declaration or file to script to insert");

        MainFunctions.setParent(this);
        MainFunctions.setToolTipText("Drag and Drop function to script to insert");
        FunctionsScroll.setViewportView(MainFunctions);
        FunctionsScroll.setPreferredSize(new Dimension(200, 400));
        FunctionsScroll.setSize(200,400);
        
        if(bJavaClientInitialized){
            MainFunctions.Initialize(PTDScriptThread.getPhantomInfo());
        }

        
        DeclsScroll.setViewportView(MainDecls);
        DeclsScroll.setPreferredSize(new Dimension(200, 400));
        DeclsScroll.setSize(200,400);
        
        MainTree.PopulateMenu((javax.swing.JMenuItem)SuiteMenu, (javax.swing.JPopupMenu)MainTree.SuitePopup);
        MainDecls.PopulateMenu((javax.swing.JMenuItem)DeclarationsModifyMenu, (javax.swing.JPopupMenu)MainDecls.DeclsPopup);
        DeclPropsPane.setViewportView(DeclProps);
        
        TreePropsPane.setViewportView(SuiteProps);
        ActiveProps = SuiteProps;
        SuiteProps.clearFields();
        TestcaseProps.clearFields();
        SuiteNameLabel.setText("Properties");
        SuiteApplyButton.setText("Apply");
        SuiteResetButton.setText("Reset");
        
        MainMenuBar.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, null);
        
        TreePane.setLeftComponent(TreeScroll);
        DeclPane.setLeftComponent(DeclsScroll);
        EditorPane.setRightComponent(EditorTabs);

        addConsolePane("Console", MainConsole);
        addScriptPane(null);
                
        TreeTabs.removeAll();
        TreeTabs.addTab("Suites", PTDImageLoader.getImageIcon(PTDImageLoader.IMG_SUITE_ICON), TreePane);
        TreeTabs.addTab("Declarations", PTDImageLoader.getImageIcon(PTDImageLoader.IMG_DECL_FILE), DeclPane);
        TreeTabs.addTab("Functions", PTDImageLoader.getImageIcon(PTDImageLoader.IMG_FUNCTIONSET_ICON), FunctionsScroll);
        
        
        EditorTabs.addCloseableTabbedPaneListener(new CloseableTabbedPaneListener(){
           public boolean closeTab(int tabIndexToClose){
               JScrollPane aScroll = (JScrollPane)EditorTabs.getComponentAt(tabIndexToClose);
               JViewport vp = aScroll.getViewport();
               PTDScriptPane aPane = (PTDScriptPane)vp.getComponent(0);
               return aPane.closeMe();
           } 
        });


        ConsoleTabs.addCloseableTabbedPaneListener(new CloseableTabbedPaneListener(){
           public boolean closeTab(int tabIndexToClose){
               Component C = ConsoleTabs.getComponentAt(tabIndexToClose);
               if(C instanceof PTDDebugPanel){
                    PTDDebugPanel D = (PTDDebugPanel)C;
                    if(currScriptThread != null){
                        if(currScriptThread.bDebug){
                            JOptionPane aPane = new JOptionPane();
                            aPane.setMessageType(aPane.QUESTION_MESSAGE);
                            aPane.setOptionType(aPane.YES_NO_OPTION);
                            int iSel = aPane.showConfirmDialog(null, "This will exit the debugger.  Continue?", "PTD", aPane.YES_NO_OPTION);
                            if(iSel == aPane.YES_OPTION){
                                DebugStopMenuActionPerformed(null);
                                currScriptThread.Kill();
                            }else{
                                return false;
                            }
                        }
                    }
               }else if(C instanceof PTDOutputPanel){
                   PTDOutputPanel D = (PTDOutputPanel)C;
                   if(D.MainScroll.getViewport().getComponent(0) instanceof PTDHTMLPane){
                       PTDHTMLPane aPane = (PTDHTMLPane)D.MainScroll.getViewport().getComponent(0);

                       if(aPane.remoteMachine != null){
                           if(aPane.remoteMachine.runState == true){
                                JOptionPane Option = new JOptionPane();
                                Option.setMessageType(Option.QUESTION_MESSAGE);
                                Option.setOptionType(Option.YES_NO_OPTION);
                                int iSel = Option.showConfirmDialog(null, "This will end remote execution on [" + aPane.remoteMachine.myName + "].  Continue?", "PTD", Option.YES_NO_OPTION);                       
                                if(iSel == JOptionPane.YES_OPTION){
                                    if(aPane.remoteMachine.CurrentThread != null){
                                        aPane.remoteMachine.CurrentThread.Kill();
                                    }else{
                                        aPane.remoteMachine.runState = false;
                                    }
                                }else{
                                 return false;  
                                }
                           }
                       }else{
                           if(aPane.getLevel() > 0){
                                JOptionPane Option = new JOptionPane();
                                Option.setMessageType(Option.QUESTION_MESSAGE);
                                Option.setOptionType(Option.YES_NO_OPTION);
                                int iSel = Option.showConfirmDialog(null, "This will stop execution.  Continue?", "PTD", Option.YES_NO_OPTION);
                                if(iSel == Option.YES_OPTION){
                                    RunStopMenuActionPerformed(null);
                                }else{
                                    return false;
                                }
                           }
                       }
                   }else if(D.MainScroll.getViewport().getComponent(0) instanceof PTDConsole){
                       PTDConsole Console = (PTDConsole)D.MainScroll.getViewport().getComponent(0);
                       Console.Kill();
                       Consoles.remove(Console);
                   }
               }
               return true;
           } 
        });
        
        
        ConsoleTabs.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                CloseableTabbedPane tabSource = (CloseableTabbedPane) e.getSource();
                processOutputChanged(tabSource);
            }
        });

        if(PTDOptions.m_DefaultWorkspace.length() > 0){
            OpenWorkspace.FileName = PTDOptions.m_DefaultWorkspace;
            OpenWorkspace.loadData(this);
        }
        
    }

    public void setDeclProps(DeclBase inProps){
        DeclProps.setProps(inProps);
    }
    
    public DeclBase getDeclProps(){
        return DeclProps.getProps();
    }
    
    public void setProps(SuiteBase inProps){
        
        if(inProps.myType == 1){
            // Suite
            SuiteNameLabel.setText("Suite Properties: " + inProps.myName);
            SuiteProps.setFields(inProps);
            TreePropsPane.setViewportView(SuiteProps);
            ActiveProps = SuiteProps;
        }else{
            // Testcase
            SuiteNameLabel.setText("Testcase Properties: " + inProps.myName);
            TestcaseProps.setFields(inProps);
            TreePropsPane.setViewportView(TestcaseProps);
            ActiveProps = TestcaseProps;
        }
    }
    
    public SuiteBase getProps(){
        ActiveProps.getFields();
        return ActiveProps.getData();
        //return ActiveProps;
        // -- SUITE MODIFIED --
        //setSuiteModified(ActiveProps.getModified());
    }
    
    private void initToolBar(){
        MainToolBar.NewScriptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileNewMenuActionPerformed(evt);
            }
        });
        MainToolBar.NewSuiteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SuiteNewMenuActionPerformed(evt);
            }
        });

        
        MainToolBar.OpenScriptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileOpenMenuActionPerformed(evt);
            }
        });
        MainToolBar.OpenSuiteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SuiteOpenMenuActionPerformed(evt);
            }
        });
        MainToolBar.OpenDeclsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeclarationsOpenMenuActionPerformed(evt);
            }
        });
        
        MainToolBar.SaveScriptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileSaveMenuActionPerformed(evt);
            }
        });
        MainToolBar.SaveAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileSaveAllMenuActionPerformed(evt);
            }
        });
        MainToolBar.SaveSuiteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SuiteSaveMenuActionPerformed(evt);
            }
        });
        MainToolBar.SaveDeclsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeclarationsSaveMenuActionPerformed(evt);
            }
        });

        
        MainToolBar.RunScriptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RunScriptMenuActionPerformed(evt);
            }
        });        
        MainToolBar.RunSuiteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RunSuiteMenuActionPerformed(evt);
            }
        }); 
        MainToolBar.StopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RunStopMenuActionPerformed(evt);
            }
        }); 
        
        MainToolBar.RecordScriptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RecordScriptMenuActionPerformed(evt);
            }
        });

        MainToolBar.RecordDeclButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RecordDeclarationsMenuActionPerformed(evt);
            }
        });

        
        MainToolBar.DebugScriptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugScriptMenuActionPerformed(evt);
            }
        });
        MainToolBar.DebugStopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugStopMenuActionPerformed(evt);
            }
        });
        MainToolBar.DebugContinueButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugContinueMenuActionPerformed(evt);
            }
        });                
        MainToolBar.DebugStepOverButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugStepOverMenuActionPerformed(evt);
            }
        });        
        MainToolBar.DebugStepIntoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugStepIntoMenuActionPerformed(evt);
            }
        });
        MainToolBar.DebugStepOutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugStepOutMenuActionPerformed(evt);
            }
        });
        MainToolBar.DebugToggleBptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugToggleBreakpointMenuActionPerformed(evt);
            }
        });
    }
    
    public void runSuite(){
        if(currScriptThread != null || bSuiteRunning){
            PTDMessageBox.MessageBox("Only one local script may run at a time.  Discontinue all running suites, testcases and scripts.");
            return;
        }
        MainTree.Run();
    }
    
    public boolean runScript(PTDScript inScript, boolean bWait){
        if(currScriptThread != null || bSuiteRunning){
            PTDMessageBox.MessageBox("Only one local script may run at a time.  Discontinue all running suites, testcases and scripts.");
            return false;
        }
        
        PTDHTMLPane aPane = new PTDHTMLPane();
        
        if(inScript.myFile == null){
            return false;
        }
        
        PTDScriptRunner aRunner = new PTDScriptRunner();
        aRunner.setOutput(aPane);
        aRunner.setComm(aPane);
        aRunner.bDoDisplay = true;
        addOutputPane("Output", aPane);

        if(aRunner.loadFile(inScript.myFile) == 0){
            aPane.displayError("File [" + inScript.myFile + "] does not exist.\n");
            return false;
        }
        
        aRunner.run(bWait, false, false);
        
        Main.debug_out("Running...");

        return false;
    }

    public boolean debugScript(PTDScript inScript, boolean bWait){
        if(currScriptThread != null || bSuiteRunning){
            PTDMessageBox.MessageBox("Only one script may run at a time.  Discontinue all running suites, testcases and scripts.");
            return false;
        }
        
        if(inScript.myFile == null){
            PTDMessageBox.MessageBox("Debugger: No script open or selected.");
            return false;
        }
        
        PTDScriptRunner aRunner = new PTDScriptRunner();
        DebugPanel.clearOutput();
        DebugPanel.initBptCmds();
        aRunner.setOutput(DebugPanel);
        aRunner.setComm(DebugPanel);        
        addDebugPane("Debugger");        

        if(aRunner.loadFile(inScript.myFile) == 0){
            DebugPanel.displayError("File [" + inScript.myFile + "] does not exist.\n");
            return false;
        }
        aRunner.run(bWait, true, false);
        
        Main.debug_out("Running...");

        return false;
    }
    
    
    public PTDHTMLPane getNewHTMLPane(String title){
        //SSI_ColorPane aPane = new SSI_ColorPane();
        PTDHTMLPane aPane = new PTDHTMLPane();
        addOutputPane(title, aPane);
        return aPane;
    }
    
    public void ApplyDecls(){
        MainDecls.updateSelectedItem();
    }
    
    
    // PTD Frame Components
    private PTDToolBar MainToolBar;
    private PTDTree MainTree;
    private PTDDecls MainDecls;
    private PTDFunctions MainFunctions;
    //private PTDConsole MainConsole;
    private Vector<PTDConsole> Consoles;
    private SSI_ColorPane MainColor;
    private CloseableTabbedPane EditorTabs;
    private CloseableTabbedPane ConsoleTabs;
    private PTDDebugPanel DebugPanel;
    private PTDRemotePanel RemotePanel;
    private JTextComponent FocusComponent;
    private PTDScriptThread currScriptThread;
    private boolean bSuiteRunning;
    
    public SuitePanelBase SuiteProps;
    public TestcasePanel TestcaseProps;
    public SuitePanelBase ActiveProps;
    public DeclPanelBase DeclProps;
    
    public PTDWorkspace OpenWorkspace;
    
    public static boolean bJavaClientInitialized = false;
    
    private boolean bSuiteModified;
    public boolean bEvaluationMode = true;
    
    public static File g_CurrentDir = null;
    
    
    
    // PTD Main Should not track suite modified either
    // -- SUITE MODIFIED --
    //public void setSuiteModified(boolean bNew){
    //    bSuiteModified = bNew;
    //}
    //public boolean getSuiteModified(){
    //    return bSuiteModified;
    //}
    
    public PTDScriptPane getActiveScriptPane(){
        int i = EditorTabs.getSelectedIndex();

        JScrollPane aScroll = (JScrollPane)EditorTabs.getSelectedComponent();
        
        if(aScroll == null){
            return null;
        }
        
        JViewport vp = aScroll.getViewport();
        PTDScriptPane aScriptPane = (PTDScriptPane)vp.getComponent(0);
        
        return aScriptPane;
    }
    
    public JTextComponent getActiveOutputPane(){
        int i = ConsoleTabs.getSelectedIndex();
        
        //JScrollPane aScroll = ConsoleTabs.getSelectedComponent();
        PTDOutputPanel aPanel = (PTDOutputPanel)ConsoleTabs.getSelectedComponent();
        
        if(aPanel == null){
            return null;
        }
        
        return (JTextComponent)aPanel.MainScroll.getViewport().getComponent(0);
        //JViewport vp = aScroll.getViewport();
        //JTextComponent aTextComponent = (JTextComponent)vp.getComponent(0);
        //return aTextComponent;
    }

    
    public void setActiveScriptPane(int Index){
        EditorTabs.setSelectedIndex(Index);
    }

    
    /*
    public JScrollPane getActiveScrollPane(){
        int i = EditorTabs.getSelectedIndex();
        JScrollPane aScroll = (JScrollPane)EditorTabs.getSelectedComponent();
        return aScroll;
    }
     **/
    
    /*
    public PTDScriptPane getActiveScriptPane(){
        int i = EditorTabs.getSelectedIndex();

        JScrollPane aScroll = (JScrollPane)EditorTabs.getSelectedComponent();
        
        if(aScroll == null){
            return null;
        }
        
        JViewport vp = aScroll.getViewport();
        PTDScriptPane aScriptPane = (PTDScriptPane)vp.getComponent(0);
        
        return aScriptPane;
    }
    */
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jFrame1 = new javax.swing.JFrame();
        MainPane = new javax.swing.JSplitPane();
        EditorPane = new javax.swing.JSplitPane();
        TreeTabs = new javax.swing.JTabbedPane();
        TreePane = new javax.swing.JSplitPane();
        TreePropsBase = new javax.swing.JPanel();
        TreePropsPane = new javax.swing.JScrollPane();
        SuiteNameLabel = new javax.swing.JLabel();
        SuiteApplyButton = new javax.swing.JButton();
        SuiteResetButton = new javax.swing.JButton();
        DeclPane = new javax.swing.JSplitPane();
        DeclPropsBase = new javax.swing.JPanel();
        DeclPropsPane = new javax.swing.JScrollPane();
        DeclsNameLabel = new javax.swing.JLabel();
        FunctionsScroll = new javax.swing.JScrollPane();
        MainMenuBar = new javax.swing.JMenuBar();
        FileMenu = new javax.swing.JMenu();
        FileNewMenu = new javax.swing.JMenuItem();
        FileOpenMenu = new javax.swing.JMenuItem();
        FileSaveMenu = new javax.swing.JMenuItem();
        FileSaveAsMenu = new javax.swing.JMenuItem();
        FileSaveAllMenu = new javax.swing.JMenuItem();
        FileCloseMenu = new javax.swing.JMenuItem();
        FileCloseAllMenu = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        FileNewWorkspaceMenu = new javax.swing.JMenuItem();
        FileOpenWorkspaceMenu = new javax.swing.JMenuItem();
        FileSaveWorkspaceMenu = new javax.swing.JMenuItem();
        FileSaveWorkspaceAsMenu = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JSeparator();
        FilePrintMenu = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        FileExitMenu = new javax.swing.JMenuItem();
        EditMenu = new javax.swing.JMenu();
        EditUndoMenu = new javax.swing.JMenuItem();
        EditRedoMenu = new javax.swing.JMenuItem();
        EditSeparator1 = new javax.swing.JSeparator();
        EditCopyMenu = new javax.swing.JMenuItem();
        EditCutMenu = new javax.swing.JMenuItem();
        EditPasteMenu = new javax.swing.JMenuItem();
        EditFindMenu = new javax.swing.JMenuItem();
        jSeparator9 = new javax.swing.JSeparator();
        EditOptionsMenu = new javax.swing.JMenuItem();
        SuiteMenu = new javax.swing.JMenu();
        SuiteNewMenu = new javax.swing.JMenuItem();
        SuiteOpenMenu = new javax.swing.JMenuItem();
        SuiteSaveMenu = new javax.swing.JMenuItem();
        SuiteSaveAsMenu = new javax.swing.JMenuItem();
        SuiteSeparatorMenu = new javax.swing.JSeparator();
        DeclararationsMenu = new javax.swing.JMenu();
        DeclarationsOpenMenu = new javax.swing.JMenuItem();
        DeclarationsCloseMenu = new javax.swing.JMenuItem();
        DeclarationsSaveMenu = new javax.swing.JMenuItem();
        DeclarationsSaveAsMenu = new javax.swing.JMenuItem();
        DeclarationsSaveAllMenu = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        DeclarationsModifyMenu = new javax.swing.JMenu();
        jSeparator6 = new javax.swing.JSeparator();
        DeclarationsRecordMenu = new javax.swing.JMenuItem();
        RunMenu = new javax.swing.JMenu();
        RunScriptMenu = new javax.swing.JMenuItem();
        RunSuiteMenu = new javax.swing.JMenuItem();
        RunConsoleMenu = new javax.swing.JMenuItem();
        RunStopMenu = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JSeparator();
        RunRemoteMenu = new javax.swing.JMenuItem();
        DebugMenu = new javax.swing.JMenu();
        DebugScriptMenu = new javax.swing.JMenuItem();
        DebugStopMenu = new javax.swing.JMenuItem();
        DebugContinueMenu = new javax.swing.JMenuItem();
        DebugStepOverMenu = new javax.swing.JMenuItem();
        DebugStepIntoMenu = new javax.swing.JMenuItem();
        DebugStepOutMenu = new javax.swing.JMenuItem();
        DebugToggleBreakpointMenu = new javax.swing.JMenuItem();
        RecordMenu = new javax.swing.JMenu();
        RecordScriptMenu = new javax.swing.JMenuItem();
        RecordDeclarationsMenu = new javax.swing.JMenuItem();
        OutputMenu = new javax.swing.JMenu();
        OutputCloseMenu = new javax.swing.JMenuItem();
        OutputCloseAllMenu = new javax.swing.JMenuItem();
        jSeparator7 = new javax.swing.JSeparator();
        OutputCollapseAllMenu = new javax.swing.JMenuItem();
        OutputExpandAllMenu = new javax.swing.JMenuItem();
        jSeparator8 = new javax.swing.JSeparator();
        OutputExportMenu = new javax.swing.JMenu();
        OutputExportTextMenu = new javax.swing.JMenuItem();
        OutputExportHTMLMenu = new javax.swing.JMenuItem();
        OutputPrintMenu = new javax.swing.JMenuItem();
        TempMenu = new javax.swing.JMenu();
        Metal = new javax.swing.JMenuItem();
        Windows = new javax.swing.JMenuItem();
        Motif = new javax.swing.JMenuItem();
        HelpMenu = new javax.swing.JMenu();
        HelpPTDHelpMenu = new javax.swing.JMenuItem();
        HelpPhantomHelpMenu = new javax.swing.JMenuItem();
        HelpAboutMenu = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Phantom Test Driver");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                onClosing(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        MainPane.setDividerSize(3);
        MainPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        MainPane.setResizeWeight(0.7);

        EditorPane.setDividerSize(3);
        EditorPane.setResizeWeight(0.1);
        EditorPane.setToolTipText("Applies the changes");

        TreeTabs.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
        TreeTabs.setFocusTraversalPolicyProvider(true);
        TreeTabs.setFont(new java.awt.Font("Arial", 0, 12));

        TreePane.setDividerSize(3);
        TreePane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        TreePane.setResizeWeight(0.5);

        TreePropsBase.setLayout(new java.awt.GridBagLayout());

        TreePropsPane.setPreferredSize(new java.awt.Dimension(100, 100));
        TreePropsPane.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                TreePropsPaneComponentResized(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        TreePropsBase.add(TreePropsPane, gridBagConstraints);

        SuiteNameLabel.setFont(new java.awt.Font("Arial", 0, 12));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 3;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
        TreePropsBase.add(SuiteNameLabel, gridBagConstraints);

        SuiteApplyButton.setFont(new java.awt.Font("Arial", 0, 12));
        SuiteApplyButton.setText("jButton1");
        SuiteApplyButton.setToolTipText("Applies the changes");
        SuiteApplyButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        SuiteApplyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SuiteApplyButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        TreePropsBase.add(SuiteApplyButton, gridBagConstraints);

        SuiteResetButton.setFont(new java.awt.Font("Arial", 0, 12));
        SuiteResetButton.setText("jButton1");
        SuiteResetButton.setToolTipText("Resets fields to original values");
        SuiteResetButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        SuiteResetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SuiteResetButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        TreePropsBase.add(SuiteResetButton, gridBagConstraints);

        TreePane.setRightComponent(TreePropsBase);

        TreeTabs.addTab("tab1", TreePane);

        DeclPane.setDividerSize(3);
        DeclPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        DeclPane.setResizeWeight(0.5);

        DeclPropsBase.setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        DeclPropsBase.add(DeclPropsPane, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        DeclPropsBase.add(DeclsNameLabel, gridBagConstraints);

        DeclPane.setRightComponent(DeclPropsBase);

        TreeTabs.addTab("tab2", DeclPane);
        TreeTabs.addTab("tab3", FunctionsScroll);

        EditorPane.setLeftComponent(TreeTabs);

        MainPane.setLeftComponent(EditorPane);

        getContentPane().add(MainPane, java.awt.BorderLayout.CENTER);

        MainMenuBar.setFont(new java.awt.Font("Courier New", 0, 12));

        FileMenu.setMnemonic('F');
        FileMenu.setText("File");
        FileMenu.setToolTipText("File Operations");
        FileMenu.setFont(new java.awt.Font("Arial", 0, 12));

        FileNewMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        FileNewMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FileNewMenu.setMnemonic('N');
        FileNewMenu.setText("New");
        FileNewMenu.setToolTipText("Create new file");
        FileNewMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileNewMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FileNewMenu);

        FileOpenMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        FileOpenMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FileOpenMenu.setMnemonic('O');
        FileOpenMenu.setText("Open");
        FileOpenMenu.setToolTipText("Open an existing script");
        FileOpenMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileOpenMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FileOpenMenu);

        FileSaveMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        FileSaveMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FileSaveMenu.setMnemonic('S');
        FileSaveMenu.setText("Save");
        FileSaveMenu.setToolTipText("Save current script");
        FileSaveMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileSaveMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FileSaveMenu);

        FileSaveAsMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        FileSaveAsMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FileSaveAsMenu.setMnemonic('A');
        FileSaveAsMenu.setText("Save As...");
        FileSaveAsMenu.setToolTipText("Save current script");
        FileSaveAsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileSaveAsMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FileSaveAsMenu);

        FileSaveAllMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FileSaveAllMenu.setMnemonic('V');
        FileSaveAllMenu.setText("Save All");
        FileSaveAllMenu.setToolTipText("Save all open scripts");
        FileSaveAllMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileSaveAllMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FileSaveAllMenu);

        FileCloseMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        FileCloseMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FileCloseMenu.setMnemonic('C');
        FileCloseMenu.setText("Close");
        FileCloseMenu.setToolTipText("Close the active script");
        FileCloseMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileCloseMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FileCloseMenu);

        FileCloseAllMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FileCloseAllMenu.setMnemonic('L');
        FileCloseAllMenu.setText("Close All");
        FileCloseAllMenu.setToolTipText("Close all open scripts");
        FileCloseAllMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileCloseAllMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FileCloseAllMenu);
        FileMenu.add(jSeparator3);

        FileNewWorkspaceMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        FileNewWorkspaceMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FileNewWorkspaceMenu.setMnemonic('w');
        FileNewWorkspaceMenu.setText("New Workspace");
        FileNewWorkspaceMenu.setToolTipText("Opens a new workspace");
        FileNewWorkspaceMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileNewWorkspaceMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FileNewWorkspaceMenu);

        FileOpenWorkspaceMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        FileOpenWorkspaceMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FileOpenWorkspaceMenu.setMnemonic('e');
        FileOpenWorkspaceMenu.setText("Open Workspace");
        FileOpenWorkspaceMenu.setToolTipText("Open a Workspace");
        FileOpenWorkspaceMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileOpenWorkspaceMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FileOpenWorkspaceMenu);

        FileSaveWorkspaceMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        FileSaveWorkspaceMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FileSaveWorkspaceMenu.setMnemonic('K');
        FileSaveWorkspaceMenu.setText("Save Workspace");
        FileSaveWorkspaceMenu.setToolTipText("Save the current workspace");
        FileSaveWorkspaceMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileSaveWorkspaceMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FileSaveWorkspaceMenu);

        FileSaveWorkspaceAsMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        FileSaveWorkspaceAsMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FileSaveWorkspaceAsMenu.setMnemonic('C');
        FileSaveWorkspaceAsMenu.setText("Save Workspace As...");
        FileSaveWorkspaceAsMenu.setToolTipText("Save the current workspace");
        FileSaveWorkspaceAsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileSaveWorkspaceAsMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FileSaveWorkspaceAsMenu);
        FileMenu.add(jSeparator4);

        FilePrintMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        FilePrintMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FilePrintMenu.setMnemonic('P');
        FilePrintMenu.setText("Print");
        FilePrintMenu.setToolTipText("Print current script");
        FilePrintMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FilePrintMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FilePrintMenu);
        FileMenu.add(jSeparator2);

        FileExitMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        FileExitMenu.setFont(new java.awt.Font("Arial", 0, 12));
        FileExitMenu.setMnemonic('X');
        FileExitMenu.setText("Exit");
        FileExitMenu.setToolTipText("Exit PTD");
        FileExitMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileExitMenuActionPerformed(evt);
            }
        });
        FileMenu.add(FileExitMenu);

        MainMenuBar.add(FileMenu);

        EditMenu.setMnemonic('E');
        EditMenu.setText("Edit");
        EditMenu.setToolTipText("Edit Operations");
        EditMenu.setFont(new java.awt.Font("Arial", 0, 12));

        EditUndoMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, java.awt.event.InputEvent.CTRL_MASK));
        EditUndoMenu.setFont(new java.awt.Font("Arial", 0, 12));
        EditUndoMenu.setMnemonic('U');
        EditUndoMenu.setText("Undo");
        EditUndoMenu.setToolTipText("Undo last text operation");
        EditUndoMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditUndoMenuActionPerformed(evt);
            }
        });
        EditMenu.add(EditUndoMenu);

        EditRedoMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Y, java.awt.event.InputEvent.CTRL_MASK));
        EditRedoMenu.setFont(new java.awt.Font("Arial", 0, 12));
        EditRedoMenu.setMnemonic('R');
        EditRedoMenu.setText("Redo");
        EditRedoMenu.setToolTipText("Redo last text operation");
        EditRedoMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditRedoMenuActionPerformed(evt);
            }
        });
        EditMenu.add(EditRedoMenu);
        EditMenu.add(EditSeparator1);

        EditCopyMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        EditCopyMenu.setFont(new java.awt.Font("Arial", 0, 12));
        EditCopyMenu.setMnemonic('C');
        EditCopyMenu.setText("Copy");
        EditCopyMenu.setToolTipText("Copy");
        EditCopyMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditCopyMenuActionPerformed(evt);
            }
        });
        EditMenu.add(EditCopyMenu);

        EditCutMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        EditCutMenu.setFont(new java.awt.Font("Arial", 0, 12));
        EditCutMenu.setMnemonic('u');
        EditCutMenu.setText("Cut");
        EditCutMenu.setToolTipText("Cut");
        EditCutMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditCutMenuActionPerformed(evt);
            }
        });
        EditMenu.add(EditCutMenu);

        EditPasteMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        EditPasteMenu.setFont(new java.awt.Font("Arial", 0, 12));
        EditPasteMenu.setMnemonic('P');
        EditPasteMenu.setText("Paste");
        EditPasteMenu.setToolTipText("Paste");
        EditPasteMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditPasteMenuActionPerformed(evt);
            }
        });
        EditMenu.add(EditPasteMenu);

        EditFindMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
        EditFindMenu.setFont(new java.awt.Font("Arial", 0, 12));
        EditFindMenu.setMnemonic('F');
        EditFindMenu.setText("Find & Replace");
        EditFindMenu.setToolTipText("Find and replace text");
        EditFindMenu.setActionCommand("Find / Replace");
        EditFindMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditFindMenuActionPerformed(evt);
            }
        });
        EditMenu.add(EditFindMenu);
        EditMenu.add(jSeparator9);

        EditOptionsMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
        EditOptionsMenu.setFont(new java.awt.Font("Arial", 0, 12));
        EditOptionsMenu.setMnemonic('O');
        EditOptionsMenu.setText("Options");
        EditOptionsMenu.setToolTipText("Edit PTD options");
        EditOptionsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditOptionsMenuActionPerformed(evt);
            }
        });
        EditMenu.add(EditOptionsMenu);

        MainMenuBar.add(EditMenu);

        SuiteMenu.setMnemonic('S');
        SuiteMenu.setText("Suite");
        SuiteMenu.setToolTipText("Suite Operations");
        SuiteMenu.setFont(new java.awt.Font("Arial", 0, 12));

        SuiteNewMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        SuiteNewMenu.setFont(new java.awt.Font("Arial", 0, 12));
        SuiteNewMenu.setMnemonic('N');
        SuiteNewMenu.setText("New");
        SuiteNewMenu.setToolTipText("Open a new suite");
        SuiteNewMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SuiteNewMenuActionPerformed(evt);
            }
        });
        SuiteMenu.add(SuiteNewMenu);

        SuiteOpenMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        SuiteOpenMenu.setFont(new java.awt.Font("Arial", 0, 12));
        SuiteOpenMenu.setMnemonic('O');
        SuiteOpenMenu.setText("Open...");
        SuiteOpenMenu.setToolTipText("Open an existing suite");
        SuiteOpenMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SuiteOpenMenuActionPerformed(evt);
            }
        });
        SuiteMenu.add(SuiteOpenMenu);

        SuiteSaveMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        SuiteSaveMenu.setFont(new java.awt.Font("Arial", 0, 12));
        SuiteSaveMenu.setMnemonic('S');
        SuiteSaveMenu.setText("Save...");
        SuiteSaveMenu.setToolTipText("Save suite");
        SuiteSaveMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SuiteSaveMenuActionPerformed(evt);
            }
        });
        SuiteMenu.add(SuiteSaveMenu);

        SuiteSaveAsMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        SuiteSaveAsMenu.setFont(new java.awt.Font("Arial", 0, 12));
        SuiteSaveAsMenu.setMnemonic('A');
        SuiteSaveAsMenu.setText("Save As...");
        SuiteSaveAsMenu.setToolTipText("Save suite");
        SuiteSaveAsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SuiteSaveAsMenuActionPerformed(evt);
            }
        });
        SuiteMenu.add(SuiteSaveAsMenu);
        SuiteMenu.add(SuiteSeparatorMenu);

        MainMenuBar.add(SuiteMenu);

        DeclararationsMenu.setMnemonic('D');
        DeclararationsMenu.setText("Declarations");
        DeclararationsMenu.setToolTipText(" Window Declarations Operations");
        DeclararationsMenu.setFont(new java.awt.Font("Arial", 0, 12));

        DeclarationsOpenMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DeclarationsOpenMenu.setMnemonic('O');
        DeclarationsOpenMenu.setText("Open");
        DeclarationsOpenMenu.setToolTipText("Open a declarations file");
        DeclarationsOpenMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeclarationsOpenMenuActionPerformed(evt);
            }
        });
        DeclararationsMenu.add(DeclarationsOpenMenu);

        DeclarationsCloseMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DeclarationsCloseMenu.setMnemonic('C');
        DeclarationsCloseMenu.setText("Close");
        DeclarationsCloseMenu.setToolTipText("Close selected declarations file");
        DeclarationsCloseMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeclarationsCloseMenuActionPerformed(evt);
            }
        });
        DeclararationsMenu.add(DeclarationsCloseMenu);

        DeclarationsSaveMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DeclarationsSaveMenu.setMnemonic('S');
        DeclarationsSaveMenu.setText("Save");
        DeclarationsSaveMenu.setToolTipText("Save selected declarations file");
        DeclarationsSaveMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeclarationsSaveMenuActionPerformed(evt);
            }
        });
        DeclararationsMenu.add(DeclarationsSaveMenu);

        DeclarationsSaveAsMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DeclarationsSaveAsMenu.setMnemonic('A');
        DeclarationsSaveAsMenu.setText("Save As...");
        DeclarationsSaveAsMenu.setToolTipText("Save selected declarations file");
        DeclarationsSaveAsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeclarationsSaveAsMenuActionPerformed(evt);
            }
        });
        DeclararationsMenu.add(DeclarationsSaveAsMenu);

        DeclarationsSaveAllMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DeclarationsSaveAllMenu.setMnemonic('L');
        DeclarationsSaveAllMenu.setText("Save All");
        DeclarationsSaveAllMenu.setToolTipText("Save all declarations files");
        DeclarationsSaveAllMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeclarationsSaveAllMenuActionPerformed(evt);
            }
        });
        DeclararationsMenu.add(DeclarationsSaveAllMenu);
        DeclararationsMenu.add(jSeparator1);

        DeclarationsModifyMenu.setMnemonic('M');
        DeclarationsModifyMenu.setText("Modify");
        DeclarationsModifyMenu.setToolTipText("Modify currenlty selected declaration");
        DeclarationsModifyMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DeclararationsMenu.add(DeclarationsModifyMenu);
        DeclararationsMenu.add(jSeparator6);

        DeclarationsRecordMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DeclarationsRecordMenu.setMnemonic('R');
        DeclarationsRecordMenu.setText("Record");
        DeclarationsRecordMenu.setToolTipText("Record declarations");
        DeclarationsRecordMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeclarationsRecordMenuActionPerformed(evt);
            }
        });
        DeclararationsMenu.add(DeclarationsRecordMenu);

        MainMenuBar.add(DeclararationsMenu);

        RunMenu.setMnemonic('R');
        RunMenu.setText("Run");
        RunMenu.setToolTipText("Run a script or suite");
        RunMenu.setFont(new java.awt.Font("Arial", 0, 12));
        RunMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RunMenuActionPerformed(evt);
            }
        });

        RunScriptMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F2, 0));
        RunScriptMenu.setFont(new java.awt.Font("Arial", 0, 12));
        RunScriptMenu.setMnemonic('S');
        RunScriptMenu.setText("Script");
        RunScriptMenu.setToolTipText("Run currently open script");
        RunScriptMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RunScriptMenuActionPerformed(evt);
            }
        });
        RunMenu.add(RunScriptMenu);

        RunSuiteMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3, 0));
        RunSuiteMenu.setFont(new java.awt.Font("Arial", 0, 12));
        RunSuiteMenu.setMnemonic('U');
        RunSuiteMenu.setText("Suite");
        RunSuiteMenu.setToolTipText("Run selected suite or testcase");
        RunSuiteMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RunSuiteMenuActionPerformed(evt);
            }
        });
        RunMenu.add(RunSuiteMenu);

        RunConsoleMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, 0));
        RunConsoleMenu.setFont(new java.awt.Font("Arial", 0, 12));
        RunConsoleMenu.setMnemonic('C');
        RunConsoleMenu.setText("Console");
        RunConsoleMenu.setToolTipText("Create a new console");
        RunConsoleMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RunConsoleMenuActionPerformed(evt);
            }
        });
        RunMenu.add(RunConsoleMenu);

        RunStopMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F2, java.awt.event.InputEvent.CTRL_MASK));
        RunStopMenu.setFont(new java.awt.Font("Arial", 0, 12));
        RunStopMenu.setMnemonic('P');
        RunStopMenu.setText("Stop");
        RunStopMenu.setEnabled(false);
        RunStopMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RunStopMenuActionPerformed(evt);
            }
        });
        RunMenu.add(RunStopMenu);
        RunMenu.add(jSeparator5);

        RunRemoteMenu.setFont(new java.awt.Font("Arial", 0, 12));
        RunRemoteMenu.setMnemonic('R');
        RunRemoteMenu.setText("Remote...");
        RunRemoteMenu.setToolTipText("Remote Execution");
        RunRemoteMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RunRemoteMenuActionPerformed(evt);
            }
        });
        RunMenu.add(RunRemoteMenu);

        MainMenuBar.add(RunMenu);

        DebugMenu.setMnemonic('G');
        DebugMenu.setText("Debug");
        DebugMenu.setToolTipText("Debug a script");
        DebugMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DebugMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugMenuActionPerformed(evt);
            }
        });

        DebugScriptMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, java.awt.event.InputEvent.CTRL_MASK));
        DebugScriptMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DebugScriptMenu.setMnemonic('S');
        DebugScriptMenu.setText("Start");
        DebugScriptMenu.setToolTipText("Begin debugging script");
        DebugScriptMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugScriptMenuActionPerformed(evt);
            }
        });
        DebugMenu.add(DebugScriptMenu);

        DebugStopMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, java.awt.event.InputEvent.SHIFT_MASK));
        DebugStopMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DebugStopMenu.setMnemonic('P');
        DebugStopMenu.setText("Stop");
        DebugStopMenu.setToolTipText("Stop debugging");
        DebugStopMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugStopMenuActionPerformed(evt);
            }
        });
        DebugMenu.add(DebugStopMenu);

        DebugContinueMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, 0));
        DebugContinueMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DebugContinueMenu.setMnemonic('C');
        DebugContinueMenu.setText("Continue");
        DebugContinueMenu.setToolTipText("Continue to next breakpoint");
        DebugContinueMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugContinueMenuActionPerformed(evt);
            }
        });
        DebugMenu.add(DebugContinueMenu);

        DebugStepOverMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F10, 0));
        DebugStepOverMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DebugStepOverMenu.setMnemonic('O');
        DebugStepOverMenu.setText("Step Over");
        DebugStepOverMenu.setToolTipText("Single step");
        DebugStepOverMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugStepOverMenuActionPerformed(evt);
            }
        });
        DebugMenu.add(DebugStepOverMenu);

        DebugStepIntoMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F11, 0));
        DebugStepIntoMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DebugStepIntoMenu.setMnemonic('I');
        DebugStepIntoMenu.setText("Step Into");
        DebugStepIntoMenu.setToolTipText("Step into a function");
        DebugStepIntoMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugStepIntoMenuActionPerformed(evt);
            }
        });
        DebugMenu.add(DebugStepIntoMenu);

        DebugStepOutMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F11, java.awt.event.InputEvent.SHIFT_MASK));
        DebugStepOutMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DebugStepOutMenu.setMnemonic('U');
        DebugStepOutMenu.setText("Step Out");
        DebugStepOutMenu.setToolTipText("Step out of a function");
        DebugStepOutMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugStepOutMenuActionPerformed(evt);
            }
        });
        DebugMenu.add(DebugStepOutMenu);

        DebugToggleBreakpointMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        DebugToggleBreakpointMenu.setFont(new java.awt.Font("Arial", 0, 12));
        DebugToggleBreakpointMenu.setMnemonic('T');
        DebugToggleBreakpointMenu.setText("Toggle Breakpoint");
        DebugToggleBreakpointMenu.setToolTipText("Toggles the breakpoint marker on the current line");
        DebugToggleBreakpointMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DebugToggleBreakpointMenuActionPerformed(evt);
            }
        });
        DebugMenu.add(DebugToggleBreakpointMenu);

        MainMenuBar.add(DebugMenu);

        RecordMenu.setMnemonic('C');
        RecordMenu.setText("Record");
        RecordMenu.setToolTipText("Record scripts or declarations");
        RecordMenu.setFont(new java.awt.Font("Arial", 0, 12));

        RecordScriptMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        RecordScriptMenu.setFont(new java.awt.Font("Arial", 0, 12));
        RecordScriptMenu.setMnemonic('S');
        RecordScriptMenu.setText("Script");
        RecordScriptMenu.setToolTipText("Record a script");
        RecordScriptMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RecordScriptMenuActionPerformed(evt);
            }
        });
        RecordMenu.add(RecordScriptMenu);

        RecordDeclarationsMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        RecordDeclarationsMenu.setFont(new java.awt.Font("Arial", 0, 12));
        RecordDeclarationsMenu.setMnemonic('D');
        RecordDeclarationsMenu.setText("Declarations");
        RecordDeclarationsMenu.setToolTipText("Record window declarations");
        RecordDeclarationsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RecordDeclarationsMenuActionPerformed(evt);
            }
        });
        RecordMenu.add(RecordDeclarationsMenu);

        MainMenuBar.add(RecordMenu);

        OutputMenu.setMnemonic('O');
        OutputMenu.setText("Output");
        OutputMenu.setFont(new java.awt.Font("Arial", 0, 12));

        OutputCloseMenu.setFont(new java.awt.Font("Arial", 0, 12));
        OutputCloseMenu.setMnemonic('c');
        OutputCloseMenu.setText("Close");
        OutputCloseMenu.setToolTipText("Close current output panel");
        OutputCloseMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OutputCloseMenuActionPerformed(evt);
            }
        });
        OutputMenu.add(OutputCloseMenu);

        OutputCloseAllMenu.setFont(new java.awt.Font("Arial", 0, 12));
        OutputCloseAllMenu.setMnemonic('a');
        OutputCloseAllMenu.setText("Close All");
        OutputCloseAllMenu.setToolTipText("Close all output panels");
        OutputCloseAllMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OutputCloseAllMenuActionPerformed(evt);
            }
        });
        OutputMenu.add(OutputCloseAllMenu);
        OutputMenu.add(jSeparator7);

        OutputCollapseAllMenu.setFont(new java.awt.Font("Arial", 0, 12));
        OutputCollapseAllMenu.setMnemonic('C');
        OutputCollapseAllMenu.setText("Collapse All");
        OutputCollapseAllMenu.setToolTipText("Collapse all Output Views");
        OutputCollapseAllMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OutputCollapseAllMenuActionPerformed(evt);
            }
        });
        OutputMenu.add(OutputCollapseAllMenu);

        OutputExpandAllMenu.setFont(new java.awt.Font("Arial", 0, 12));
        OutputExpandAllMenu.setMnemonic('E');
        OutputExpandAllMenu.setText("Expand All");
        OutputExpandAllMenu.setToolTipText("Expand all Output Views");
        OutputExpandAllMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OutputExpandAllMenuActionPerformed(evt);
            }
        });
        OutputMenu.add(OutputExpandAllMenu);
        OutputMenu.add(jSeparator8);

        OutputExportMenu.setMnemonic('X');
        OutputExportMenu.setText("Export As...");
        OutputExportMenu.setToolTipText("Export the output");
        OutputExportMenu.setFont(new java.awt.Font("Arial", 0, 12));

        OutputExportTextMenu.setFont(new java.awt.Font("Arial", 0, 12));
        OutputExportTextMenu.setMnemonic('T');
        OutputExportTextMenu.setText("Text");
        OutputExportTextMenu.setToolTipText("Export Output as Text");
        OutputExportTextMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OutputExportTextMenuActionPerformed(evt);
            }
        });
        OutputExportMenu.add(OutputExportTextMenu);

        OutputExportHTMLMenu.setFont(new java.awt.Font("Arial", 0, 12));
        OutputExportHTMLMenu.setMnemonic('H');
        OutputExportHTMLMenu.setText("HTML");
        OutputExportHTMLMenu.setToolTipText("Export output as HTML");
        OutputExportHTMLMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OutputExportHTMLMenuActionPerformed(evt);
            }
        });
        OutputExportMenu.add(OutputExportHTMLMenu);

        OutputMenu.add(OutputExportMenu);

        OutputPrintMenu.setFont(new java.awt.Font("Arial", 0, 12));
        OutputPrintMenu.setMnemonic('P');
        OutputPrintMenu.setText("Print");
        OutputPrintMenu.setToolTipText("Send output to printer");
        OutputPrintMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OutputPrintMenuActionPerformed(evt);
            }
        });
        OutputMenu.add(OutputPrintMenu);

        MainMenuBar.add(OutputMenu);

        TempMenu.setText("L & F");
        TempMenu.setFont(new java.awt.Font("Arial", 0, 12));

        Metal.setFont(new java.awt.Font("Arial", 0, 12));
        Metal.setText("Metal");
        Metal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MetalActionPerformed(evt);
            }
        });
        TempMenu.add(Metal);

        Windows.setFont(new java.awt.Font("Arial", 0, 12));
        Windows.setText("Windows");
        Windows.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                WindowsActionPerformed(evt);
            }
        });
        TempMenu.add(Windows);

        Motif.setFont(new java.awt.Font("Arial", 0, 12));
        Motif.setText("Motif");
        Motif.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MotifActionPerformed(evt);
            }
        });
        TempMenu.add(Motif);

        MainMenuBar.add(TempMenu);

        HelpMenu.setMnemonic('H');
        HelpMenu.setText("Help");
        HelpMenu.setToolTipText("View Help");
        HelpMenu.setFont(new java.awt.Font("Arial", 0, 12));

        HelpPTDHelpMenu.setFont(new java.awt.Font("Arial", 0, 12));
        HelpPTDHelpMenu.setMnemonic('P');
        HelpPTDHelpMenu.setText("PTD Help");
        HelpPTDHelpMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HelpPTDHelpMenuActionPerformed(evt);
            }
        });
        HelpMenu.add(HelpPTDHelpMenu);

        HelpPhantomHelpMenu.setFont(new java.awt.Font("Arial", 0, 12));
        HelpPhantomHelpMenu.setMnemonic('h');
        HelpPhantomHelpMenu.setText("Phantom Help");
        HelpPhantomHelpMenu.setToolTipText("View help about Phantom");
        HelpPhantomHelpMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HelpPhantomHelpMenuActionPerformed(evt);
            }
        });
        HelpMenu.add(HelpPhantomHelpMenu);

        HelpAboutMenu.setFont(new java.awt.Font("Arial", 0, 12));
        HelpAboutMenu.setMnemonic('A');
        HelpAboutMenu.setText("About PTD");
        HelpAboutMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HelpAboutMenuActionPerformed(evt);
            }
        });
        HelpMenu.add(HelpAboutMenu);

        MainMenuBar.add(HelpMenu);

        setJMenuBar(MainMenuBar);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void SuiteResetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SuiteResetButtonActionPerformed
        MainTree.resetSelectedItem();
    }//GEN-LAST:event_SuiteResetButtonActionPerformed

    private void SuiteApplyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SuiteApplyButtonActionPerformed
        MainTree.updateSelectedItem();
    }//GEN-LAST:event_SuiteApplyButtonActionPerformed

    private void MotifActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MotifActionPerformed
        //com.sun.java.swing.plaf.motif.MotifLookAndFeel;
        try{
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
        }catch(Exception e){
            Main.debug_out(e.getMessage());
        }
        SwingUtilities.updateComponentTreeUI(this);
        pack();
    }//GEN-LAST:event_MotifActionPerformed

    private void WindowsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_WindowsActionPerformed
        try{
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }catch(Exception e){
            Main.debug_out(e.getMessage());
        }
        SwingUtilities.updateComponentTreeUI(this);
        pack();
    }//GEN-LAST:event_WindowsActionPerformed

    private void MetalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MetalActionPerformed
        try{
            MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        }catch(Exception e){
            Main.debug_out(e.getMessage());
        }
        SwingUtilities.updateComponentTreeUI(this);
        pack();
        
    }//GEN-LAST:event_MetalActionPerformed

    private void TreePropsPaneComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_TreePropsPaneComponentResized
        
    }//GEN-LAST:event_TreePropsPaneComponentResized

    private void FileExitMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileExitMenuActionPerformed
        if(processClose()){
            dispose();
            System.exit(0);
        }
    }//GEN-LAST:event_FileExitMenuActionPerformed

    private void DeclarationsSaveAsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeclarationsSaveAsMenuActionPerformed

        JFileChooser aChooser = new JFileChooser();
        PTDFileFilter dec_filter = new PTDFileFilter("dec", "Window Declarations File (.dec)");
        aChooser.setCurrentDirectory(PTDMain.g_CurrentDir);
        aChooser.addChoosableFileFilter(dec_filter);
        
        int result = aChooser.showSaveDialog(this);
        if(result == JFileChooser.CANCEL_OPTION){
            return;
        }
        
        try {            
            File afile = aChooser.getSelectedFile();
            PTDMain.g_CurrentDir = afile.getParentFile();
            String sPath = afile.getAbsolutePath();
            
            String sName = afile.getName();
            if(sName.indexOf(".") < 0){
                sPath = sPath + ".dec";
            }
            
            MainDecls.saveFile(sPath,null);
        }catch(Exception e){
            Main.debug_out(e.getMessage());
        }
    }//GEN-LAST:event_DeclarationsSaveAsMenuActionPerformed

    private void DeclarationsRecordMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeclarationsRecordMenuActionPerformed
            //PTDMessageBox aMsg = new PTDMessageBox("BETA: Use WinDR.exe for now.");
            //aMsg.setVisible(true);
        Process proc = ssi_executor.Execute(Main.getAppDir() + "/WinDR.exe");
        if(proc == null){
            PTDMessageBox aMsg = new PTDMessageBox("Cannot find WinDR.exe.  Reinstall PTD.");
            aMsg.setVisible(true);
        }
    }//GEN-LAST:event_DeclarationsRecordMenuActionPerformed

    private void DeclarationsSaveAllMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeclarationsSaveAllMenuActionPerformed
        MainDecls.saveAll();
    }//GEN-LAST:event_DeclarationsSaveAllMenuActionPerformed

    private void DeclarationsSaveMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeclarationsSaveMenuActionPerformed
        MainDecls.saveFile("",null);
    }//GEN-LAST:event_DeclarationsSaveMenuActionPerformed

    private void DeclarationsCloseMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeclarationsCloseMenuActionPerformed
        MainDecls.closeFile();
    }//GEN-LAST:event_DeclarationsCloseMenuActionPerformed

    private void DeclarationsOpenMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeclarationsOpenMenuActionPerformed
       
        JFileChooser aChooser = new JFileChooser();
        PTDFileFilter decl_filter = new PTDFileFilter("dec", "Window Declarations File (.dec)");
        aChooser.setCurrentDirectory(PTDMain.g_CurrentDir);
        aChooser.addChoosableFileFilter(decl_filter);
        
        int result = aChooser.showOpenDialog(this);
        if(result == JFileChooser.CANCEL_OPTION){
            return;
        }
        
        try {            
            File afile = aChooser.getSelectedFile();
            PTDMain.g_CurrentDir = afile.getParentFile();
            MainDecls.addFile(afile.getAbsolutePath());
            //MainTree.loadFromFile(afile.getAbsolutePath());
        }catch(Exception e){
            Main.debug_out(e.getMessage());
        }
        
        TreeTabs.setSelectedIndex(1);

    }//GEN-LAST:event_DeclarationsOpenMenuActionPerformed

    private void DebugContinueMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DebugContinueMenuActionPerformed
        DebugPanel.go();
    }//GEN-LAST:event_DebugContinueMenuActionPerformed

    private void EditFindMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditFindMenuActionPerformed
        
        PTDFindReplace aFind = new PTDFindReplace();
        aFind.setParent(this);
        aFind.setVisible(true);
        //PTDScriptPane aPane = getActiveScriptPane();
        //if(aPane == null){
        //    return;
        //}
        //aPane.SearchNext(0, "the");
    }//GEN-LAST:event_EditFindMenuActionPerformed

    private void RunConsoleMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RunConsoleMenuActionPerformed
        PTDConsole newConsole = new PTDConsole();
        newConsole.StartThread();
        Consoles.add(newConsole);
        addConsolePane("Console", newConsole);
    }//GEN-LAST:event_RunConsoleMenuActionPerformed

    private void EditOptionsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditOptionsMenuActionPerformed
        PTDOptionsFrame aFrame = new PTDOptionsFrame();
        aFrame.setVisible(true);
    }//GEN-LAST:event_EditOptionsMenuActionPerformed

    static public boolean performSaveAs(PTDScriptPane aPane){
        if(aPane == null){
            return false;
        }
        
        JFileChooser aChooser = new JFileChooser();
        PTDFileFilter psc_filter = new PTDFileFilter("psc", "Phantom Script (.psc)");
        aChooser.setCurrentDirectory(PTDMain.g_CurrentDir);
        aChooser.addChoosableFileFilter(psc_filter);
        
        int result = aChooser.showSaveDialog(aPane);
        if(result == JFileChooser.CANCEL_OPTION){
            return false;
        }
        
        try {            
            File afile = aChooser.getSelectedFile();
            PTDMain.g_CurrentDir = afile.getParentFile();
            String sPath = afile.getAbsolutePath();
            String sName = afile.getName();
            if(sName.indexOf('.') < 0){
                sPath = sPath + ".psc";
            }
            
            if(afile.exists()){
                JOptionPane anOption = new JOptionPane();
                int o = anOption.showConfirmDialog(null, "File exists. Overwrite?", "Confirm Overwrite", anOption.OK_CANCEL_OPTION);
                if(o == anOption.CANCEL_OPTION){
                    return false;
                }
            }
                        
            PTDScript aScript = aPane.getScript();
            aScript.myName = sPath;
            aScript.myFile = sPath;
            aPane.setScript(aScript);
            aPane.saveFile(aScript.myFile);
            
        }catch(Exception e){
            Main.debug_out(e.getMessage());
        }
        return true;
        
    }

    public void performOutputExport(int Type){

        PTDOutputPanel aPanel = (PTDOutputPanel)ConsoleTabs.getSelectedComponent();
        PTDHTMLPane aPane = null;
        if(aPanel.MainScroll.getViewport().getComponent(0) instanceof PTDHTMLPane){
            aPane = (PTDHTMLPane)aPanel.MainScroll.getViewport().getComponent(0);
        }else{
            return;
        }

        if(aPane == null){
            return;
        }
        
        JFileChooser aChooser = new JFileChooser();
        PTDFileFilter file_filter;
        if(Type == 0){
            file_filter = new PTDFileFilter("txt", "Text Document (.txt)");
    
        }else{
            file_filter = new PTDFileFilter("html", "HTML Document (.html)");
        }
        aChooser.setCurrentDirectory(PTDMain.g_CurrentDir);
        aChooser.addChoosableFileFilter(file_filter);
        
        int result = aChooser.showSaveDialog(aPane);
        if(result == JFileChooser.CANCEL_OPTION){
            return;
        }
        
        try {            
            File afile = aChooser.getSelectedFile();
            PTDMain.g_CurrentDir = afile.getParentFile();
            if(afile.exists()){
                JOptionPane anOption = new JOptionPane();
                int o = anOption.showConfirmDialog(null, "File exists. Overwrite?", "Confirm Overwrite", anOption.OK_CANCEL_OPTION);
                if(o == anOption.CANCEL_OPTION){
                    return;
                }
            }
           
            String sName = afile.getName();
            String s = afile.getAbsolutePath();
            
            if(sName.indexOf('.') < 0){
                if(Type == 0){
                    s = s + ".txt";
                }else{
                    s = s + ".html";
                }
            }

            
            aPane.export(s, Type);
            
        }catch(Exception e){
            Main.debug_out(e.getMessage());
        }
    }    
    
    public void testMessage(){
        PTDMessageBox.MessageBox("Command Recieved");
    }
    
    public PTDSuiteDisplay getCurrentOutput(){
        // Change this, lest active output pane changes
        PTDOutputPanel aPanel = (PTDOutputPanel)ConsoleTabs.getSelectedComponent();
        PTDHTMLPane aPane = (PTDHTMLPane)aPanel.MainScroll.getViewport().getComponent(0);

        if(aPane == null){
            return null;
        }
        
        return aPane.OutputDisplay;
    }
    
    public boolean performSuiteSaveAs(){
        JFileChooser aChooser = new JFileChooser();
        PTDFileFilter sui_filter = new PTDFileFilter("sui", "PTD Suite File (.sui)");
        aChooser.setCurrentDirectory(PTDMain.g_CurrentDir);
        aChooser.addChoosableFileFilter(sui_filter);
        
        int result = aChooser.showSaveDialog(this);
        if(result == JFileChooser.CANCEL_OPTION){
            return false;
        }
        
        try {            
            File afile = aChooser.getSelectedFile();
            PTDMain.g_CurrentDir = afile.getParentFile();
            String sPath = afile.getAbsolutePath();
            String sName = afile.getName();
            if(sName.indexOf('.') < 0){
                sPath = sPath + ".sui";
            }
            MainTree.saveToFile(sPath);
        }catch(Exception e){
            Main.debug_out(e.getMessage());
        }
        return true;        
    }

    
    private void FileSaveAsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileSaveAsMenuActionPerformed
        Main.debug_out("File Save As Selected");
        PTDScriptPane aPane = getActiveScriptPane();
        int iActive = EditorTabs.getSelectedIndex();
        if(performSaveAs(aPane)){
            PTDScript aScript = aPane.getScript();
            EditorTabs.setTitleAt(iActive, EditorTabs.modifyTitle(aScript.myFile));
        }
    }//GEN-LAST:event_FileSaveAsMenuActionPerformed

    private void DebugMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DebugMenuActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_DebugMenuActionPerformed

    private void DebugStepOutMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DebugStepOutMenuActionPerformed
        DebugPanel.stepOut();
    }//GEN-LAST:event_DebugStepOutMenuActionPerformed

    private void DebugStopMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DebugStopMenuActionPerformed
        DebugPanel.stop();
    }//GEN-LAST:event_DebugStopMenuActionPerformed

    private void DebugStepOverMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DebugStepOverMenuActionPerformed
        DebugPanel.stepOver();
    }//GEN-LAST:event_DebugStepOverMenuActionPerformed

    private void DebugStepIntoMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DebugStepIntoMenuActionPerformed
        DebugPanel.stepInto();
    }//GEN-LAST:event_DebugStepIntoMenuActionPerformed

    private void DebugScriptMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DebugScriptMenuActionPerformed
        PTDScriptPane aScriptPane = getActiveScriptPane();
        if(aScriptPane == null){
            return;
        }
        
        if(aScriptPane.saveMeConfirm() == false){
            return;
        }
        
        updateEditorTabTitles();
        
        PTDScript SelScript = aScriptPane.getScript(); //(PTDScript)ScriptCollection.get(i);
        if(SelScript == null){
            return;
        }

        debugScript(SelScript, false);
    }//GEN-LAST:event_DebugScriptMenuActionPerformed

    private void EditCopyMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditCopyMenuActionPerformed
        if(FocusComponent != null){
            FocusComponent.copy();
        }
    }//GEN-LAST:event_EditCopyMenuActionPerformed

    private void EditCutMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditCutMenuActionPerformed
        //PTDScriptPane aPane = getActiveScriptPane();
        //if(aPane == null){
        //    return;
        //}        
        //aPane.cut();
        if(FocusComponent != null){
            FocusComponent.cut();
        }

    }//GEN-LAST:event_EditCutMenuActionPerformed

    private void EditPasteMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditPasteMenuActionPerformed
        //PTDScriptPane aPane = getActiveScriptPane();
        //if(aPane == null){
        //    return;
        //}
        //aPane.paste();
        if(FocusComponent != null){
            FocusComponent.paste();
        }

    }//GEN-LAST:event_EditPasteMenuActionPerformed

    private void EditRedoMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditRedoMenuActionPerformed
        PTDScriptPane aPane = getActiveScriptPane();
        if(aPane == null){
            return;
        }
        aPane.ra.actionPerformed(evt);
    }//GEN-LAST:event_EditRedoMenuActionPerformed

    private void EditUndoMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditUndoMenuActionPerformed
        PTDScriptPane aPane = getActiveScriptPane();
        if(aPane == null){
            return;
        }
        aPane.ua.actionPerformed(evt);
    }//GEN-LAST:event_EditUndoMenuActionPerformed

    private void SuiteNewMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SuiteNewMenuActionPerformed
        if(!MainTree.closeMe()){
            return;
        }
        MainTree.newSuite();
    }//GEN-LAST:event_SuiteNewMenuActionPerformed

    private void RecordDeclarationsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RecordDeclarationsMenuActionPerformed
        //PTDMessageBox aMsg = new PTDMessageBox("BETA: Use WinDR.exe for now.");
        //aMsg.setVisible(true);
        Process proc = ssi_executor.Execute(Main.getAppDir() + "/WinDR.exe");
        if(proc == null){
            PTDMessageBox aMsg = new PTDMessageBox("Cannot find WinDR.exe.  Reinstall PTD.");
            aMsg.setVisible(true);
        }

    }//GEN-LAST:event_RecordDeclarationsMenuActionPerformed

    private void RecordScriptMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RecordScriptMenuActionPerformed
        Main.debug_out("Record Script selected");
        addScriptPane(null);
        PTDScriptPane aPane = getActiveScriptPane();
        
        PTDRecorderThread aThread = new PTDRecorderThread(aPane);
        aThread.start();        
    }//GEN-LAST:event_RecordScriptMenuActionPerformed

    private void RunSuiteMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RunSuiteMenuActionPerformed
        runSuite();
        // TODO add your handling code here:
    }//GEN-LAST:event_RunSuiteMenuActionPerformed

    private void FilePrintMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FilePrintMenuActionPerformed
        // got code from http://www.codecomments.com/message197072.html
        
        PrinterJob job = PrinterJob.getPrinterJob();
        PTDScriptPane activePane = getActiveScriptPane();
        
        if(activePane == null){
            return;
        }

        //Printable P = activePane.getPrintable(null, null);
        //job.setPrintable(P);
        
        job.setPrintable(activePane);
        activePane.PrintName = CloseableTabbedPane.modifyTitle(activePane.getScript().myName);
        job.setJobName("PTD: " + activePane.PrintName);
        if (job.printDialog()) 
        {
            try{
                job.print();
            }catch (Exception ex){
                Main.debug_out(ex.getMessage());
            }
        }
    }//GEN-LAST:event_FilePrintMenuActionPerformed

    private void SuiteSaveAsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SuiteSaveAsMenuActionPerformed
        Main.debug_out("Save Suite As Selected");        
        performSuiteSaveAs();
       

    }//GEN-LAST:event_SuiteSaveAsMenuActionPerformed

    private void SuiteOpenMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SuiteOpenMenuActionPerformed
        Main.debug_out("Open Suite Selected");
       
        if(!MainTree.closeMe()){
            return;
        }
        
        JFileChooser aChooser = new JFileChooser();
        PTDFileFilter sui_filter = new PTDFileFilter("sui", "PTD Suite File (.sui)");
        aChooser.setCurrentDirectory(PTDMain.g_CurrentDir);
        aChooser.addChoosableFileFilter(sui_filter);
        
        int result = aChooser.showOpenDialog(this);
        if(result == JFileChooser.CANCEL_OPTION){
            return;
        }
        
        try {            
            File afile = aChooser.getSelectedFile();
            PTDMain.g_CurrentDir = afile.getParentFile();
            loadSuite(afile.getAbsolutePath());
        }catch(Exception e){
            Main.debug_out(e.getMessage());
        }

    }//GEN-LAST:event_SuiteOpenMenuActionPerformed

    private void SuiteSaveMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SuiteSaveMenuActionPerformed
        //String testFile = "c:\\test.sui";
        if(MainTree.SuiteFile.length() > 0){
            MainTree.saveToFile(MainTree.SuiteFile);
        }else{
            SuiteSaveAsMenuActionPerformed(evt);
        }
    }//GEN-LAST:event_SuiteSaveMenuActionPerformed

    private void RunMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RunMenuActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_RunMenuActionPerformed

    private void FileSaveMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileSaveMenuActionPerformed
        Main.debug_out("Save Selected");
       
        int i = EditorTabs.getSelectedIndex();
        
        if(i < 0){
            return;
        }
        
        JScrollPane aScroll = (JScrollPane)EditorTabs.getSelectedComponent();
	JViewport vp = aScroll.getViewport();
        PTDScriptPane aPane = (PTDScriptPane)vp.getComponent(0);
        aPane.saveMe();
        if(aPane.getScript() != null){
            EditorTabs.setTitleAt(i, EditorTabs.modifyTitle(aPane.getScript().myFile));
        }
        
    }//GEN-LAST:event_FileSaveMenuActionPerformed

    private void RunScriptMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RunScriptMenuActionPerformed
        //SSI_ColorPane aPane = new SSI_ColorPane();

        PTDScriptPane aScriptPane = getActiveScriptPane();
        if(aScriptPane == null){
            return;
        }
        
        if(aScriptPane.saveMeConfirm() == false){
            return;
        }
        
        updateEditorTabTitles();
        
        PTDScript SelScript = aScriptPane.getScript(); //(PTDScript)ScriptCollection.get(i);
        if(SelScript == null){
            return;
        }

        runScript(SelScript, false);
    }//GEN-LAST:event_RunScriptMenuActionPerformed

    private void onClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_onClosing
        // Add any other cleanup stuff here...
        if(processClose()){
            dispose();
            System.exit(0);
        }
        
    }//GEN-LAST:event_onClosing

    private void FileOpenMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileOpenMenuActionPerformed
// TODO add your handling code here:
        Main.debug_out("Open Selected");
       
        JFileChooser aChooser = new JFileChooser();
        PTDFileFilter psc_filter = new PTDFileFilter("psc", "Phantom Scripts (.psc)");
        aChooser.setCurrentDirectory(PTDMain.g_CurrentDir);
        aChooser.addChoosableFileFilter(psc_filter);
        
        int result = aChooser.showOpenDialog(this);
        if(result == JFileChooser.CANCEL_OPTION){
            return;
        }
        
        try {            
            File afile = aChooser.getSelectedFile();
            PTDMain.g_CurrentDir = afile.getParentFile();
            addScriptPane(afile.getAbsolutePath());
        }catch(Exception e){
            Main.debug_out(e.getMessage());
        }
        
    }//GEN-LAST:event_FileOpenMenuActionPerformed

    private void FileNewMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileNewMenuActionPerformed
        // TODO add your handling code here:
        Main.debug_out("New selected");
        addScriptPane(null);
    }//GEN-LAST:event_FileNewMenuActionPerformed

    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        //Main.debug_out("Resizing...");
    }//GEN-LAST:event_formComponentResized

private void OutputPrintMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OutputPrintMenuActionPerformed
    Main.debug_out("Printing Output...");
    
    PrinterJob job = PrinterJob.getPrinterJob();
    PTDOutputPanel aPanel = (PTDOutputPanel)ConsoleTabs.getSelectedComponent();
    Component C = aPanel.MainScroll.getViewport().getView();
    if(C instanceof PTDHTMLPane){
        PTDHTMLPane aPane = (PTDHTMLPane)aPanel.MainScroll.getViewport().getComponent(0);
        aPane.Bounder.isInitialized = false;
        job.setPrintable(aPane);
    }else if(C instanceof PTDConsole){
        PTDConsole aConsole = (PTDConsole)aPanel.MainScroll.getViewport().getComponent(0);
        job.setPrintable(aConsole);
    }else{
        return;
    }
    
    //PrintRequestAttributeSet Attr = new PrintRequestAttributeSet();
    
    if (job.printDialog()) 
    {
        try{
            //job.getPageFormat(job.getPrintService().getAttributes());
            job.print();
        }catch (Exception ex){
            Main.debug_out(ex.getMessage());
        }
    }
}//GEN-LAST:event_OutputPrintMenuActionPerformed

private void OutputCollapseAllMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OutputCollapseAllMenuActionPerformed
    PTDOutputPanel aPanel = (PTDOutputPanel)ConsoleTabs.getSelectedComponent();
    if((PTDHTMLPane)aPanel.MainScroll.getViewport().getComponent(0) instanceof PTDHTMLPane){
        PTDHTMLPane aPane = (PTDHTMLPane)aPanel.MainScroll.getViewport().getComponent(0);
        aPane.collapseAll();
    }
}//GEN-LAST:event_OutputCollapseAllMenuActionPerformed

private void OutputExpandAllMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OutputExpandAllMenuActionPerformed
    PTDOutputPanel aPanel = (PTDOutputPanel)ConsoleTabs.getSelectedComponent();
    if((PTDHTMLPane)aPanel.MainScroll.getViewport().getComponent(0) instanceof PTDHTMLPane){
        PTDHTMLPane aPane = (PTDHTMLPane)aPanel.MainScroll.getViewport().getComponent(0);
        aPane.expandAll();
    }
}//GEN-LAST:event_OutputExpandAllMenuActionPerformed

private void OutputExportTextMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OutputExportTextMenuActionPerformed
    performOutputExport(0);
}//GEN-LAST:event_OutputExportTextMenuActionPerformed

private void OutputExportHTMLMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OutputExportHTMLMenuActionPerformed
    performOutputExport(1);
}//GEN-LAST:event_OutputExportHTMLMenuActionPerformed

private void RunStopMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RunStopMenuActionPerformed
    if(currScriptThread != null){
        currScriptThread.Kill();
    }
    bSuiteRunning = false;
}//GEN-LAST:event_RunStopMenuActionPerformed

private void FileSaveWorkspaceMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileSaveWorkspaceMenuActionPerformed
    OpenWorkspace.saveData(this, false);
}//GEN-LAST:event_FileSaveWorkspaceMenuActionPerformed

private void FileOpenWorkspaceMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileOpenWorkspaceMenuActionPerformed
    
    if(OpenWorkspace.requestFileName(JFileChooser.OPEN_DIALOG) == false){
        return;
    }
    OpenWorkspace.loadData(this);
}//GEN-LAST:event_FileOpenWorkspaceMenuActionPerformed

private void FileCloseMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileCloseMenuActionPerformed
    PTDScriptPane aPane = getActiveScriptPane();
    if(aPane != null){
        if(aPane.closeMe() == false){
            return;
        }
        EditorTabs.remove(EditorTabs.getSelectedComponent());
    }
    
}//GEN-LAST:event_FileCloseMenuActionPerformed

private void FileCloseAllMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileCloseAllMenuActionPerformed
    closeAllScripts();
}//GEN-LAST:event_FileCloseAllMenuActionPerformed

private void FileSaveWorkspaceAsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileSaveWorkspaceAsMenuActionPerformed
    OpenWorkspace.saveData(this, true);
}//GEN-LAST:event_FileSaveWorkspaceAsMenuActionPerformed

private void DebugToggleBreakpointMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DebugToggleBreakpointMenuActionPerformed
        PTDScriptPane aScriptPane = getActiveScriptPane();
        if(aScriptPane == null){
            return;
        }

        aScriptPane.toggleBreakpoint();
}//GEN-LAST:event_DebugToggleBreakpointMenuActionPerformed

private void FileSaveAllMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileSaveAllMenuActionPerformed
    saveAll();
}//GEN-LAST:event_FileSaveAllMenuActionPerformed

private void HelpPTDHelpMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HelpPTDHelpMenuActionPerformed
    OpenHelpFile("/PTDHelp/PTDHelp.hs", "PTD Help");  
}//GEN-LAST:event_HelpPTDHelpMenuActionPerformed

private void RunRemoteMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RunRemoteMenuActionPerformed
    PTDRemoteFrame aFrame = new PTDRemoteFrame();
    aFrame.initialize(MainTree, this);
    aFrame.setVisible(true);
}//GEN-LAST:event_RunRemoteMenuActionPerformed

private void HelpAboutMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HelpAboutMenuActionPerformed
        PTDAboutBox aBox = new PTDAboutBox();
        aBox.setVisible(true);
}//GEN-LAST:event_HelpAboutMenuActionPerformed

private void FileNewWorkspaceMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileNewWorkspaceMenuActionPerformed
    if(saveConfirm("Do you want to save the current workspace?", "Save current workspace?") == JOptionPane.YES_OPTION){
        OpenWorkspace.saveData(this, false);
    }
    clearWorkspace();
    OpenWorkspace.clear();
}//GEN-LAST:event_FileNewWorkspaceMenuActionPerformed

private void OutputCloseMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OutputCloseMenuActionPerformed
    int i = ConsoleTabs.getSelectedIndex();
    ConsoleTabs.closeTab(i);
}//GEN-LAST:event_OutputCloseMenuActionPerformed

private void OutputCloseAllMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OutputCloseAllMenuActionPerformed
        int cCnt = ConsoleTabs.getTabCount();
        int ctr = 0;        
        
        // Must do reverse
        for(ctr = (cCnt-1); ctr >= 0; ctr--){
            //JScrollPane aScroll = (JScrollPane)ConsoleTabs.getComponentAt(ctr);
            //JViewport vp = aScroll.getViewport();            
            Component C = ConsoleTabs.getComponentAt(ctr);
            if(C instanceof PTDOutputPanel){
                PTDOutputPanel D = (PTDOutputPanel)C;
                if(D.MainScroll.getViewport().getComponent(0) instanceof PTDHTMLPane){
                    ConsoleTabs.closeTab(ctr);
                }
            }            
        }
}//GEN-LAST:event_OutputCloseAllMenuActionPerformed

private void HelpPhantomHelpMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HelpPhantomHelpMenuActionPerformed
    OpenHelpFile("/PhantomHelp/Phantom Help.hs", "Phantom Help");  
}//GEN-LAST:event_HelpPhantomHelpMenuActionPerformed
    
    // -----------------------------------------------------
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PTDMain().setVisible(true);
            }
        });
    }
    
    // -----------------------------------------------------
    // Performs closing operations, including saving scripts and
    // closing consoles.
    public boolean processClose(){
        int cCnt= EditorTabs.getTabCount();
        int ctr = 0;

        if(OpenWorkspace.FileName.length() > 0){
            OpenWorkspace.saveData(this, false);
        }else{
            JOptionPane aPane = new JOptionPane();
            aPane.setMessageType(aPane.QUESTION_MESSAGE);
            aPane.setOptionType(aPane.YES_NO_CANCEL_OPTION);
            int iSel = aPane.showConfirmDialog(this, "Do you want to save your workspace?", "Save Workspace", aPane.YES_NO_CANCEL_OPTION);
            if(iSel == JOptionPane.CANCEL_OPTION){
                return false;
            }else if(iSel == JOptionPane.YES_OPTION){
                if(!OpenWorkspace.saveData(this, true)){
                    return false;
                }
            }
        }
        
        for(ctr = 0; ctr < cCnt; ctr++){
            JScrollPane aScroll = (JScrollPane)EditorTabs.getComponentAt(ctr);
            JViewport vp = aScroll.getViewport();
            PTDScriptPane aPane = (PTDScriptPane)vp.getComponent(0);
            if(aPane.bChanged){
                EditorTabs.setSelectedIndex(ctr);
                if(!aPane.closeMe()){
                    updateEditorTabTitles();
                    return false;
                }
            }
        }
        
        if(!MainDecls.closeMe()){
            return false;
        }
        
        if(!MainTree.closeMe()){
            return false;
        }
        

        cCnt = Consoles.size();        
        for(ctr = 0; ctr < cCnt; ctr++){
            ((PTDConsole)Consoles.get(ctr)).Kill();
        }
        Consoles.clear(); 
        return true;
    }
    
    // -----------------------------------------------------
    public void saveAll(){
        int ctr; 
        int cCnt= EditorTabs.getTabCount();
        for(ctr = 0; ctr < cCnt; ctr++){
            JScrollPane aScroll = (JScrollPane)EditorTabs.getComponentAt(ctr);
            JViewport vp = aScroll.getViewport();
            PTDScriptPane aPane = (PTDScriptPane)vp.getComponent(0);
            if(aPane.bChanged){
                EditorTabs.setSelectedIndex(ctr);
                if(!aPane.saveMe()){
                    updateEditorTabTitles();
                    return;
                }
            }
        }
        updateEditorTabTitles();
    }
        
    // -----------------------------------------------------
    public void setWorkspaceTitle(String WS){
        String sTitle;
        if(WS.length() > 0){
            sTitle = WS + " - Phantom Test Driver";
        }else{
            sTitle = "Phantom Test Driver";
        }
        if(bEvaluationMode == true){
            sTitle = sTitle + " [EVALUATION COPY]";
        }
        setTitle(sTitle);
    }    
    
    // -----------------------------------------------------
    public int getScriptPaneCount(){
        return EditorTabs.getTabCount();
    }
    
    // -----------------------------------------------------
    public PTDScriptPane getScriptPaneByIndex(int Index){
        JScrollPane aScroll;
        JViewport vp;
        PTDScriptPane aScriptPane = null;
        PTDScript aScript = null;
        
        aScroll = (JScrollPane)EditorTabs.getComponentAt(Index);
        if(aScroll == null){
           return null;
        }
        vp = aScroll.getViewport();
        aScriptPane = (PTDScriptPane)vp.getComponent(0);
        return aScriptPane;
    }

    // -----------------------------------------------------
    public int findPaneIndexByFile(String fileName){
        int cnt = EditorTabs.getTabCount();
        int ctr = 0;
        int iRet = -1;
        JScrollPane aScroll;
        JViewport vp;
        PTDScriptPane aScriptPane = null;
        PTDScript aScript = null;
        //Ret = null;
        
        if(fileName == null){
            return -1;
        }
        
        for(ctr = 0; ctr < cnt; ctr++){
            //EditorTabs.getT
            aScroll = (JScrollPane)EditorTabs.getComponentAt(ctr);
            if(aScroll == null){
                return -1;
            }
            vp = aScroll.getViewport();
            aScriptPane = (PTDScriptPane)vp.getComponent(0);
            aScript = aScriptPane.getScript();
            if(aScript == null){
                return -1;
            }
            
            if(aScript.myFile != null){
                if(fileName.compareToIgnoreCase(aScript.myFile) == 0){
                    //Ret = aScriptPane;
                    iRet = ctr;
                }
            }
        }

        return iRet;
    }

    // ----------------------------------------------------- 
    public String getSuiteFile(){
        return MainTree.SuiteFile;
    }
    
    // ----------------------------------------------------- 
    public Vector<String> getOpenDecls(){        
        return MainDecls.getLoadedDecs();
    }
    
    // ----------------------------------------------------- 
    public Vector<String> getOpenScripts(){
        Vector<String> Ret = new Vector<String>();
        int cCnt= EditorTabs.getTabCount();
        for(int ctr = 0; ctr < cCnt; ctr++){
            JScrollPane aScroll = (JScrollPane)EditorTabs.getComponentAt(ctr);
            JViewport vp = aScroll.getViewport();
            PTDScriptPane aPane = (PTDScriptPane)vp.getComponent(0);
            if(aPane != null){
                PTDScript aScript = aPane.getScript();
                if(aScript != null){
                    if(aScript.myFile != null){
                        Ret.add(aScript.myFile);
                    }
                }
            }
        }
        return Ret;
    }
    // ----------------------------------------------------- 

    public boolean closeAllScripts(){
        int cCnt= EditorTabs.getTabCount();
        for(int ctr = (cCnt-1); ctr >= 0; ctr--){
            JScrollPane aScroll = (JScrollPane)EditorTabs.getComponentAt(ctr);
            JViewport vp = aScroll.getViewport();
            PTDScriptPane aPane = (PTDScriptPane)vp.getComponent(0);
            if(aPane != null){
                if(aPane.closeMe() == false){
                    updateEditorTabTitles();
                    return false;
                }
                EditorTabs.remove(ctr);
            }
        }      
        return true;
    }
    
    
    // ----------------------------------------------------- 
    public boolean clearWorkspace(){
        int cCnt= EditorTabs.getTabCount();
        if(!closeAllScripts()){
            return false;
        }
        
        if(!MainTree.closeMe()){
            return false;
        }
        MainTree.newSuite();
        
        if(!MainDecls.closeMe()){
            return false;
        }
        MainDecls.initTree();
        
        setWorkspaceTitle("");
        
        // Dont want this because this function only clears the view
        //OpenWorkspace.clear();
        return true;
    }
    
    // ----------------------------------------------------- 
    public boolean loadScripts(Vector<String> Scripts){
        for(int i = 0; i < Scripts.size(); i++){
            addScriptPane(Scripts.get(i));
        }
        if(EditorTabs.getTabCount() > 0){
            EditorTabs.setSelectedIndex(0);
        }
        return true;
    }

    // ----------------------------------------------------- 
    public boolean loadDecls(Vector<String> Decls){
        for(int i = 0; i < Decls.size(); i++){
            MainDecls.addFile(Decls.get(i));
        }
        return true;
    }
    
    // ----------------------------------------------------- 
    public boolean loadSuite(String FileName){
        MainTree.loadFromFile(FileName);
        return true;
    }
    
    // ----------------------------------------------------- 
    public void updateEditorTabTitles(){
        // Changes title of tabs based on whether they are modified
        // Used when exit cancel, and some of the testcases are modified.
        // Also used for script run and debug, although there it only
        // modifies the running script, as that should be the only one
        // it saves.  Perhaps later, can add index to this that can be null
        // to update only one title.
        
        int cCnt= EditorTabs.getTabCount();
        int ctr = 0;
        for(ctr = 0; ctr < cCnt; ctr++){
            JScrollPane aScroll = (JScrollPane)EditorTabs.getComponentAt(ctr);
            JViewport vp = aScroll.getViewport();
            PTDScriptPane aPane = (PTDScriptPane)vp.getComponent(0);
            String s = "Untitled";
            if(aPane != null){
                PTDScript aScript = aPane.getScript();
                if(aScript != null){
                    s = aScript.myName;
                }
                if(aPane.bChanged){
                    EditorTabs.setTitleAt(ctr, EditorTabs.modifyTitle(s) + " *");
                }else{
                    EditorTabs.setTitleAt(ctr, EditorTabs.modifyTitle(s));
                }
            }
        }
    }

    // -----------------------------------------------------
    public int addScriptPane(String fileName) {
        PTDScriptPane aPane = null;
        int iPane;
        String Title;
        if(fileName != null){
            fileName = fileName.trim();
        }
        iPane = findPaneIndexByFile(fileName);        
        if(iPane >= 0){
            // Dont re-open
            setActiveScriptPane(iPane);
            return 1;
        }
        
        
        PTDScript aScript = new PTDScript();
        JScrollPane aScroll = new JScrollPane();
        

        aPane = new PTDScriptPane();
        aPane.addFocusListener(myFocusListener);
        aPane.MyDebug = this.DebugPanel;
        
        //EmptyBorder aBorder = new EmptyBorder(10, 10, 10, 10);
        //aPane.setBorder(aBorder);
        
        if(fileName == null){
            aScript.myName = "Untitled";
            aScript.myFile = null;
        }else{
            aPane.loadFile(fileName);
            aScript.myName = fileName;
            aScript.myFile = fileName;
        }
        
	JViewport vp = aScroll.getViewport();
	vp.add(aPane);
	vp.setBackingStoreEnabled(true);

        //LineNumberView aLineNumView = new LineNumberView(aPane);
        aScroll.setRowHeaderView(aPane.MyLineNumView);
        
        aPane.setScript(aScript);
        EditorTabs.addTab(EditorTabs.modifyTitle(aScript.myName), aScroll, PTDImageLoader.getImageIcon(PTDImageLoader.IMG_TAB_SCRIPT));
        EditorTabs.setSelectedIndex(EditorTabs.indexOfComponent(aScroll));
        
        aPane.getDocument().addDocumentListener(new DocumentListener(){
            public void changedUpdate(DocumentEvent e){
                changeTitle(EditorTabs.getSelectedIndex());
            }
            public void insertUpdate(DocumentEvent e){
                changeTitle(EditorTabs.getSelectedIndex());
            }
            public void removeUpdate(DocumentEvent e){
                changeTitle(EditorTabs.getSelectedIndex());
            }
            
            public void changeTitle(int index){
                String s = EditorTabs.getTitleAt(index);
                if(s.indexOf("*") < 0){
                    s = s + " *";
                }
                EditorTabs.setTitleAt(index, s);

            }
        });
        
        return 1;
    }
    
    public void removeScriptPane(int index) {
        //ScriptCollection.remove(index);
        //PTDScriptPane aPane = new PTDScriptPane();
    }

    // -----------------------------------------------------
    public int addConsolePane(String Name, JEditorPane newPane) {
        
        PTDOutputPanel aPanel = new PTDOutputPanel();
        
        newPane.addFocusListener(myFocusListener);

        aPanel.MainScroll.setViewportView(newPane);
        ConsoleTabs.add(aPanel, Name);

        int Index = ConsoleTabs.indexOfComponent(aPanel);
        ConsoleTabs.setSelectedIndex(Index);
        processOutputChanged(ConsoleTabs);
        return 1;
    }

    // -----------------------------------------------------
    public int addOutputPane(String Name, PTDHTMLPane newPane) {
        // This has to be different, because need to have scroll position for output
        
        PTDOutputPanel aPanel = new PTDOutputPanel();
        
        newPane.addFocusListener(myFocusListener);

        newPane.VertBar = aPanel.MainScroll.getVerticalScrollBar();
        //newPane.InputPanel = aPanel.getInputPanel();
        //newPane.setInput(aPanel.getInput());
        aPanel.MainScroll.setViewportView(newPane);
        ConsoleTabs.add(aPanel, Name);

        int Index = ConsoleTabs.indexOfComponent(aPanel);
        ConsoleTabs.setSelectedIndex(Index);

        processOutputChanged(ConsoleTabs);
        
        return 1;
    }

    // -----------------------------------------------------
    public void addDebugPane(String Name) {
        int cnt = ConsoleTabs.getTabCount();
        for(int ctr = 0; ctr < cnt; ctr++){
            if(ConsoleTabs.getComponentAt(ctr) instanceof PTDDebugPanel){
                ConsoleTabs.setSelectedIndex(ctr);
                processOutputChanged(ConsoleTabs);
                return;
            }
        }
        
        ConsoleTabs.add(DebugPanel, Name);
        int Index = ConsoleTabs.indexOfComponent(DebugPanel);
        ConsoleTabs.setSelectedIndex(Index);
        processOutputChanged(ConsoleTabs);
    }

    // -----------------------------------------------------
    public void addRemotePane(String Name) {
        int cnt = ConsoleTabs.getTabCount();
        for(int ctr = 0; ctr < cnt; ctr++){
            if(ConsoleTabs.getComponentAt(ctr) instanceof PTDRemotePanel){
                ConsoleTabs.setSelectedIndex(ctr);
                processOutputChanged(ConsoleTabs);
                return;
            }
        }
        
        ConsoleTabs.add(RemotePanel, Name);
        int Index = ConsoleTabs.indexOfComponent(RemotePanel);
        ConsoleTabs.setSelectedIndex(Index);
        processOutputChanged(ConsoleTabs);
    }
    
    
    public void readOptions(){
        PTDOptions.loadFromFile(PTDOptions.getOptionsFile());
    }
    
    public static int saveConfirm(String Message, String Title){
        JOptionPane aPane = new JOptionPane();
        aPane.setMessageType(aPane.QUESTION_MESSAGE);
        aPane.setOptionType(aPane.YES_NO_CANCEL_OPTION);
        
        int iSel = aPane.showConfirmDialog(Main.getMainFrame(), Message, Title, aPane.YES_NO_CANCEL_OPTION);
        return iSel;
    }
    
    public static String openPSCFile(){
        String Ret = "";
        JFileChooser aChooser = new JFileChooser();
        //aChooser.
        PTDFileFilter fun_filter = new PTDFileFilter("fun", "Phantom Functions (.fun)");
        PTDFileFilter psc_filter = new PTDFileFilter("psc", "Phantom Scripts (.psc)");
        aChooser.setCurrentDirectory(PTDMain.g_CurrentDir);
        aChooser.addChoosableFileFilter(fun_filter);
        aChooser.addChoosableFileFilter(psc_filter);
        
        int result = aChooser.showOpenDialog(Main.getMainFrame());
        if(result == JFileChooser.CANCEL_OPTION){
            return Ret;
        }
        
        try {            
            File afile = aChooser.getSelectedFile();
            PTDMain.g_CurrentDir = afile.getParentFile();
            return afile.getAbsolutePath();
            //addScriptPane(afile.getAbsolutePath());
        }catch(Exception e){
            Main.debug_out(e.getMessage());
        }
        return Ret;

    }
    
    public void processOutputChanged(CloseableTabbedPane tabSource){
        int i = tabSource.getSelectedIndex();
        int c = tabSource.getTabCount();
        if(i >= tabSource.getTabCount() || i < 0){
            OutputMenu.setEnabled(false);
            return;
        }
        
        String tab = tabSource.getTitleAt(i);

        if(tabSource.getSelectedComponent() instanceof PTDDebugPanel){
            OutputMenu.setEnabled(false);
            return;
        }

        if(tabSource.getSelectedComponent() instanceof PTDRemotePanel){
            OutputMenu.setEnabled(false);
            return;
        }

        
        PTDOutputPanel aPanel = (PTDOutputPanel)tabSource.getSelectedComponent();
        if(aPanel != null){
            //aPanel.MainScroll.getViewport().getC
            Component C = aPanel.MainScroll.getViewport().getView();
            if(C != null){
                if(C instanceof PTDConsole){
                    OutputMenu.setEnabled(true);
                    OutputExportMenu.setEnabled(false);
                    OutputCollapseAllMenu.setEnabled(false);
                    OutputExpandAllMenu.setEnabled(false);
                    OutputPrintMenu.setEnabled(true);
                }else if(C instanceof PTDHTMLPane){
                    OutputMenu.setEnabled(true);
                    OutputExportMenu.setEnabled(true);
                    OutputCollapseAllMenu.setEnabled(true);
                    OutputExpandAllMenu.setEnabled(true);
                    OutputPrintMenu.setEnabled(true);
                }else{
                    OutputMenu.setEnabled(false);
                }
            }
        }
   }
    
   public void setCurrentScriptThread(PTDScriptThread In){
       currScriptThread = In;
       if(bSuiteRunning){
           return;
       }
       if(In != null){
           setRunMenus(true);
           if(In.bDebug == true){
               setDebugMenus(true);
           }
       }else{
           setRunMenus(false);
           setDebugMenus(false);
       }
   } 
   
   public PTDScriptThread getCurrentScriptThread(){
       return currScriptThread;
   }
   
   public void setRunMenus(boolean bRunning){
      if(bRunning == false){
           DebugScriptMenu.setEnabled(true);
           RunScriptMenu.setEnabled(true);
           RunSuiteMenu.setEnabled(true);
           RunStopMenu.setEnabled(false);
           MainToolBar.DebugScriptButton.setEnabled(true);
           MainToolBar.RunScriptButton.setEnabled(true);
           MainToolBar.RunSuiteButton.setEnabled(true);
           MainTree.RunMenu.setEnabled(true);
       }else{
           DebugScriptMenu.setEnabled(false);
           RunScriptMenu.setEnabled(false);
           RunSuiteMenu.setEnabled(false);
           RunStopMenu.setEnabled(true);
           MainToolBar.DebugScriptButton.setEnabled(true);
           MainToolBar.RunScriptButton.setEnabled(true);
           MainToolBar.RunSuiteButton.setEnabled(true);
           MainToolBar.DebugScriptButton.setEnabled(false);
           MainToolBar.RunScriptButton.setEnabled(false);
           MainToolBar.RunSuiteButton.setEnabled(false);           
           MainTree.RunMenu.setEnabled(false);
       }
   }
   
   public void setDebugMenus(boolean bDebugging){
      if(bDebugging == false){
           DebugContinueMenu.setEnabled(false);
           DebugStepOverMenu.setEnabled(false);
           DebugStepOutMenu.setEnabled(false);
           DebugStepIntoMenu.setEnabled(false);
           DebugStopMenu.setEnabled(false);
       }else{
           DebugContinueMenu.setEnabled(true);
           DebugStepOverMenu.setEnabled(true);
           DebugStepOutMenu.setEnabled(true);
           DebugStepIntoMenu.setEnabled(true);
           DebugStopMenu.setEnabled(true);
       }
   }
   
   public boolean getSuiteRunning(){
       return bSuiteRunning;
   }
      
   public void setSuiteRunning(boolean b){
       setRunMenus(b);
       setDebugMenus(false);
       bSuiteRunning = b;
   }
   
   public void addRemoteMachine(PTDRemoteMachine aMachine){
    addRemotePane("Remote");
    RemotePanel.addMachine(aMachine);
   }
   
   public void OpenHelpFile(String Path, String Title){
           
        // This is taken from the JHelpDev HelpViewer source code
        ActionEvent cshAction = new ActionEvent(new JLabel(),  ActionEvent.ACTION_FIRST, null);
        try{   
           HelpSet mainHelpSet = null;
           HelpBroker mainHelpBroker = null;
            try {
                URL hsURL = new File(Main.getHelpDir() + Path).toURL();
                mainHelpSet = new HelpSet(null, hsURL);
            } catch (Exception ee) {
                Main.debug_out(ee.getMessage());
                PTDMessageBox.MessageBox("Could not open help file.  Reinstall PTD.");
                return;
            }

            if (mainHelpSet != null){
                mainHelpBroker = mainHelpSet.createHelpBroker();
            }else{
               PTDMessageBox.MessageBox("Could not open help file.  Reinstall PTD.");
               return;
            }
            if (mainHelpBroker != null) {
                //mainHelpBroker.setLocation(loc);
                //mainHelpBroker.setSize(dimension);
                //if (mainHelpBroker.getHelpSet().getNavigatorView(nav) != null)
                //    mainHelpBroker.setCurrentView(nav);
   
                mainHelpSet.setTitle(Title);
                ImageIcon a = PTDImageLoader.getImageIcon(PTDImageLoader.IMG_PTD_ICON);                        
                new CSH.DisplayHelpFromSource(mainHelpBroker).actionPerformed(cshAction);
                WindowPresentation wp = ((DefaultHelpBroker)mainHelpBroker).getWindowPresentation();
                JFrame helpwindow = (JFrame)wp.getHelpWindow();
                helpwindow.setIconImage(a.getImage());
            }else{
               PTDMessageBox.MessageBox("Could not open help file.  Reinstall PTD.");
               return;
            }
           
            //ClassLoader C = this.getClass().getClassLoader();
            
            //URL hsURL = HelpSet.findHelpSet(this.getClass().getClassLoader(), "./help/PTDHelp/PTDHelp");
            //HelpSet mainHelpSet = new HelpSet(null, hsURL);

            
            //URL url = new URL("file:///" + Main.getHelpDir() + Path);
            //HelpSet hs = new HelpSet(C, url);
            //C:\Projects\Java\javahelp-1_1_3\jh1.1.3\javahelp\bin
                    
            //HelpSet hs = new HelpSet(null, url);
            
            //hs.setTitle(Title);
            //JHelp jh = new JHelp(hs);
            
            //jh.setVisible(true);
          
            /*
            Presentation P = MainWindow.getPresentation(hs, Title);
            hs.setTitle(Title);
            
            P.setDisplayed(true);
            
            if(P instanceof MainWindow){
                MainWindow W = (MainWindow)P;
                Window Q = W.getHelpWindow();
                if(Q != null){
                    if(Q instanceof JFrame){
                        JFrame J = (JFrame)Q;
                        ImageIcon a = PTDImageLoader.getImageIcon(PTDImageLoader.IMG_PTD_ICON);
                        J.setIconImage(a.getImage());
                    }
                }
            }
             * */
        } catch (Exception ex) {
            Main.debug_out(ex.getMessage());
            PTDMessageBox.MessageBox("Could not open help file.  Reinstall PTD.");
        }
   }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem DebugContinueMenu;
    private javax.swing.JMenu DebugMenu;
    private javax.swing.JMenuItem DebugScriptMenu;
    private javax.swing.JMenuItem DebugStepIntoMenu;
    private javax.swing.JMenuItem DebugStepOutMenu;
    private javax.swing.JMenuItem DebugStepOverMenu;
    private javax.swing.JMenuItem DebugStopMenu;
    private javax.swing.JMenuItem DebugToggleBreakpointMenu;
    private javax.swing.JSplitPane DeclPane;
    private javax.swing.JPanel DeclPropsBase;
    private javax.swing.JScrollPane DeclPropsPane;
    private javax.swing.JMenu DeclararationsMenu;
    private javax.swing.JMenuItem DeclarationsCloseMenu;
    private javax.swing.JMenu DeclarationsModifyMenu;
    private javax.swing.JMenuItem DeclarationsOpenMenu;
    private javax.swing.JMenuItem DeclarationsRecordMenu;
    private javax.swing.JMenuItem DeclarationsSaveAllMenu;
    private javax.swing.JMenuItem DeclarationsSaveAsMenu;
    private javax.swing.JMenuItem DeclarationsSaveMenu;
    private javax.swing.JLabel DeclsNameLabel;
    private javax.swing.JMenuItem EditCopyMenu;
    private javax.swing.JMenuItem EditCutMenu;
    private javax.swing.JMenuItem EditFindMenu;
    private javax.swing.JMenu EditMenu;
    private javax.swing.JMenuItem EditOptionsMenu;
    private javax.swing.JMenuItem EditPasteMenu;
    private javax.swing.JMenuItem EditRedoMenu;
    private javax.swing.JSeparator EditSeparator1;
    private javax.swing.JMenuItem EditUndoMenu;
    private javax.swing.JSplitPane EditorPane;
    private javax.swing.JMenuItem FileCloseAllMenu;
    private javax.swing.JMenuItem FileCloseMenu;
    private javax.swing.JMenuItem FileExitMenu;
    private javax.swing.JMenu FileMenu;
    private javax.swing.JMenuItem FileNewMenu;
    private javax.swing.JMenuItem FileNewWorkspaceMenu;
    private javax.swing.JMenuItem FileOpenMenu;
    private javax.swing.JMenuItem FileOpenWorkspaceMenu;
    private javax.swing.JMenuItem FilePrintMenu;
    private javax.swing.JMenuItem FileSaveAllMenu;
    private javax.swing.JMenuItem FileSaveAsMenu;
    private javax.swing.JMenuItem FileSaveMenu;
    private javax.swing.JMenuItem FileSaveWorkspaceAsMenu;
    private javax.swing.JMenuItem FileSaveWorkspaceMenu;
    private javax.swing.JScrollPane FunctionsScroll;
    private javax.swing.JMenuItem HelpAboutMenu;
    private javax.swing.JMenu HelpMenu;
    private javax.swing.JMenuItem HelpPTDHelpMenu;
    private javax.swing.JMenuItem HelpPhantomHelpMenu;
    private javax.swing.JMenuBar MainMenuBar;
    private javax.swing.JSplitPane MainPane;
    private javax.swing.JMenuItem Metal;
    private javax.swing.JMenuItem Motif;
    private javax.swing.JMenuItem OutputCloseAllMenu;
    private javax.swing.JMenuItem OutputCloseMenu;
    private javax.swing.JMenuItem OutputCollapseAllMenu;
    private javax.swing.JMenuItem OutputExpandAllMenu;
    private javax.swing.JMenuItem OutputExportHTMLMenu;
    private javax.swing.JMenu OutputExportMenu;
    private javax.swing.JMenuItem OutputExportTextMenu;
    private javax.swing.JMenu OutputMenu;
    private javax.swing.JMenuItem OutputPrintMenu;
    private javax.swing.JMenuItem RecordDeclarationsMenu;
    private javax.swing.JMenu RecordMenu;
    private javax.swing.JMenuItem RecordScriptMenu;
    private javax.swing.JMenuItem RunConsoleMenu;
    private javax.swing.JMenu RunMenu;
    private javax.swing.JMenuItem RunRemoteMenu;
    private javax.swing.JMenuItem RunScriptMenu;
    private javax.swing.JMenuItem RunStopMenu;
    private javax.swing.JMenuItem RunSuiteMenu;
    private javax.swing.JButton SuiteApplyButton;
    private javax.swing.JMenu SuiteMenu;
    private javax.swing.JLabel SuiteNameLabel;
    private javax.swing.JMenuItem SuiteNewMenu;
    private javax.swing.JMenuItem SuiteOpenMenu;
    private javax.swing.JButton SuiteResetButton;
    private javax.swing.JMenuItem SuiteSaveAsMenu;
    private javax.swing.JMenuItem SuiteSaveMenu;
    private javax.swing.JSeparator SuiteSeparatorMenu;
    private javax.swing.JMenu TempMenu;
    private javax.swing.JSplitPane TreePane;
    private javax.swing.JPanel TreePropsBase;
    private javax.swing.JScrollPane TreePropsPane;
    private javax.swing.JTabbedPane TreeTabs;
    private javax.swing.JMenuItem Windows;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JSeparator jSeparator8;
    private javax.swing.JSeparator jSeparator9;
    // End of variables declaration//GEN-END:variables
    
}
